mysql_query() в PHP - скрытая угроза. Тест производительности с кавычками на PHP
Feb 02

Очень полезная и чесно пизженная функция с каментов на php.net с минимальными изменениями, помогает для отлова узких мест в скрипте и настройки производительности функций/методов

<?php
function debug() {
   static $start_time = NULL;
   static $start_code_line = 0;

   $call_info = array_shift( debug_backtrace() );
   $code_line = $call_info['line'];
   $file = array_pop( explode('/', $call_info['file']));

   if( $start_time === NULL ) {
       print 'debug '.$file.'> initialize'."\n";
       $start_time = time() + microtime();
       $start_code_line = $code_line;
       return 0;
   }

   printf('debug %s> code-lines: %d-%d time: %.4f mem: %d/%d KB'."\n", $file, $start_code_line, $code_line, (time() + microtime() - $start_time), ceil(memory_get_usage()/1024), ceil(memory_get_usage(1)/1024));
   $start_time = time() + microtime();
   $start_code_line = $code_line;
}
?>

Примеры вывода:

debug PHP-1.php> code-lines: 9-9 time: 0.1213 mem: 58/256 KB
debug PHP-1.php> code-lines: 9-9 time: 0.1205 mem: 58/256 KB
debug PHP-1.php> code-lines: 9-9 time: 0.1212 mem: 58/256 KB
debug PHP-1.php> code-lines: 9-9 time: 0.1227 mem: 58/256 KB
debug PHP-1.php> initialize
debug PHP-1.php> code-lines: 6-6 time: 0.0498 mem: 7206/7424 KB
debug PHP-1.php> code-lines: 6-6 time: 0.0526 mem: 14358/14592 KB
debug PHP-1.php> code-lines: 6-6 time: 0.0593 mem: 22023/22272 KB
debug PHP-1.php> code-lines: 6-6 time: 0.0463 mem: 28664/28672 KB

Но эта функция также не показывает буффер mysql_query :)

No related posts.

One Response to “PHP debug() функция”

  1. Kul Says:

    чет комментов нету) рекламу сайтега делай)

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a