9¸ö±ØÐëÖªµÀµÄʵÓÃPHPº¯ÊýºÍ¹¦ÄÜ(3)
ͨ¹ýÕì²â½Å±¾µÄÄÚ´æʹÓÃÇé¿ö£¬ÓÐÀûÓÚ´úÂëµÄÓÅ»¯¡£PHP ÌṩÁËÒ»¸öÀ¬»øÊÕ¼¯Æ÷ºÍÒ»¸ö·Ç³£¸´ÔÓµÄÄÚ´æ¹ÜÀíÆ÷¡£½Å±¾Ö´ÐÐʱËùʹÓõÄÄÚ´æÁ¿£¬ÓÐÉýÓеø¡£ÎªÁ˵õ½µ±Ç°µÄÄÚ´æʹÓÃÇé¿ö£¬ÎÒÃÇ¿ÉÒÔʹÓà memory_get_usage() º¯Êý¡£Èç¹ûÐèÒª»ñµÃÈÎÒâʱ¼äµãµÄ×î¸ßÄÚ´æʹÓÃÁ¿£¬Ôò¿ÉÒÔʹÓà memory_limit() º¯Êý¡£
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º echo "Initial: ".memory_get_usage()." bytes \n"; /* prints Initial: 361400 bytes */ // let's use up some memory for ($i = 0; $i < 100000; $i++) { $array []= md5($i); } // let's remove half of the array for ($i = 0; $i < 100000; $i++) { unset($array[$i]); } echo "Final: ".memory_get_usage()." bytes \n"; /* prints Final: 885912 bytes */ echo "Peak: ".memory_get_peak_usage()." bytes \n"; /* prints Peak: 13687072 bytes */4¡¢CPU ʹÓÃÐÅÏ¢
Ϊ´Ë£¬ÎÒÃÇÒªÀûÓà getrusage() º¯Êý¡£Çë¼ÇסÕâ¸öº¯Êý²»ÊÊÓÃÓÚ Windows ƽ̨¡£
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º print_r(getrusage()); /* prints Array ( [ru_oublock] => 0 [ru_inblock] => 0 [ru_msgsnd] => 2 [ru_msgrcv] => 3 [ru_maxrss] => 12692 [ru_ixrss] => 764 [ru_idrss] => 3864 [ru_minflt] => 94 [ru_majflt] => 0 [ru_nsignals] => 1 [ru_nvcsw] => 67 [ru_nivcsw] => 4 [ru_nswap] => 0 [ru_utime.tv_usec] => 0 [ru_utime.tv_sec] => 0 [ru_stime.tv_usec] => 6269R-LEFT: #0099cc 1px solid; TABLE-LAYOUT: fixed; BORDER-TOP: #0099cc 1px solid; BORDER-RIGHT: #0099cc 1px solid" border="0" cellspacing="0" cellpadding="6" width="95%" align="center"> ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º // yes, the argument list can be empty function foo() { // returns an array of all passed arguments $args = func_get_args(); foreach ($args as $k => $v) { echo "arg".($k+1).": $v\n"; } } foo(); /* prints nothing */ foo('hello'); /* prints arg1: hello */ foo('hello', 'world', 'again'); /* prints arg1: hello arg2: world arg3: again */oluntary context switches
ru_nivcsw: involuntary context switches
ru_nswap: swaps
ru_utime.tv_usec: user time used (microseconds)
ru_utime.tv_sec: user time used (seconds)
ru_stime.tv_usec: system time used (microseconds)
ru_stime.tv_sec: system time used (seconds)
ÒªÖªµÀ½Å±¾ÏûºÄ¶àÉÙ CPU ¹¦ÂÊ£¬ÎÒÃÇÐèÒª¿´¿´ ¡®user time¡¯ ºÍ ¡¯system time¡¯ Á½¸ö²ÎÊýµÄÖµ¡£ÃëºÍ΢Ã벿·ÖĬÈÏÊǵ¥¶ÀÌṩµÄ¡£Äã¿ÉÒÔ³ýÒÔ 100 Íò΢Ã룬²¢¼ÓÉÏÃëµÄ²ÎÊýÖµ£¬µÃµ½Ò»¸öÊ®½øÖƵÄ×ÜÃëÊý¡£ÈÃÎÒÃÇÀ´¿´Ò»¸öÀý×Ó£º
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º // sleep for 3 seconds (non-busy) sleep(3); $data = getrusage(); echo "User time: ". ($data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000); echo "System time: ". ($data['ru_stime.tv_sec'] + $data['ru_stime.tv_usec'] / 1000000); /* prints User time: 0.011552 System time: 0 */¾¡¹Ü½Å±¾ÔËÐÐÓÃÁË´óÔ¼ 3 ÃëÖÓ£¬CPU ʹÓÃÂÊÈ´·Ç³£·Ç³£µÍ¡£ÒòΪÔÚ˯ÃßÔËÐеĹý³ÌÖУ¬¸Ã½Å±¾Êµ¼ÊÉϲ»ÏûºÄ CPU ×ÊÔ´¡£»¹ÓÐÐí¶àÆäËûµÄÈÎÎñ£¬¿ÉÄÜÐèÒªÒ»¶Îʱ¼ä£¬µ«²»Õ¼ÓÃÀàËƵȴý´ÅÅ̲Ù×÷µÈ CPU ʱ¼ä¡£Òò´ËÕýÈçÄãËù¿´µ½µÄ£¬CPU ʹÓÃÂʺÍÔËÐÐʱ¼äµÄʵ¼Ê³¤¶È²¢²»×ÜÊÇÏàͬµÄ¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º // loop 10 million times (busy) for($i=0;$i<10000000;$i++) { } $data = getrusage(); echo "User time: ". ($data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000); echo "System time: ". ($data['ru_stime.tv_sec'] + $data['ru_stime.tv_usec'] / 1000000); /* prints User time: 1.424592 System time: 0.004204 */Õ⻨ÁË´óÔ¼ 1.4 ÃëµÄ CPU ʱ¼ä£¬µ«¼¸ºõ¶¼ÊÇÓû§Ê±¼ä£¬ÒòΪûÓÐϵͳµ÷Óá£ÏµÍ³Ê±¼äÊÇÖ¸»¨·ÑÔÚÖ´ÐгÌÐòµÄϵͳµ÷ÓÃʱµÄ CPU ¿ªÏú¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º $start = microtime(true); // keep calling microtime for about 3 seconds while(microtime(true) - $start < 3) { } $data = getrusage(); echo "User time: ". ($data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000); echo "System time: ". ($data['ru_stime.tv_sec'] + $data['ru_stime.tv_usec'] / 1000000); /* prints User time: 1.088171 System time: 1.675315 */ÏÖÔÚÎÒÃÇÓÐÏ൱¶àµÄϵͳʱ¼äÕ¼Óá£ÕâÊÇÒòΪ½Å±¾¶à´Îµ÷Óà microtime() º¯Êý£¬¸Ãº¯ÊýÐèÒªÏò²Ù×÷ϵͳ·¢³öÇëÇó£¬ÒÔ»ñÈ¡ËùÐèʱ¼ä¡£ÄãÒ²¿ÉÄÜ»á×¢Òâµ½ÔËÐÐʱ¼ä¼ÓÆðÀ´²»µ½ 3 Ãë¡£ÕâÊÇÒòΪÓпÉÄÜÔÚ·þÎñÆ÷ÉÏͬʱ´æÔÚÆäËû½ø³Ì£¬²¢Çҽű¾Ã»ÓÐ 100% ʹÓà CPU µÄÕû¸ö 3 Ãë³ÖÐøʱ¼ä¡£
5¡¢Ä§Êõ³£Á¿
PHP ÌṩÁË»ñÈ¡µ±Ç°ÐкŠ(__LINE__)¡¢Îļþ·¾¶ (__FILE__)¡¢Ä¿Â¼Â·¾¶ (__DIR__)¡¢º¯ÊýÃû (__FUNCTION__)¡¢ÀàÃû (__CLASS__)¡¢·½·¨Ãû (__METHOD__) ºÍÃüÃû¿Õ¼ä (__NAMESPACE__) µÈÓÐÓõÄħÊõ³£Á¿¡£ÔÚÕâƪÎÄÕÂÖв»×÷Ò»Ò»½éÉÜ£¬µ«ÊÇÎÒ½«¸æËßÄãһЩÓÃÀý¡£µ±°üº¬ÆäËû½Å±¾Îļþʱ£¬Ê¹Óà __FILE__ ³£Á¿£¨»òÕßʹÓà PHP5.3 оßÓÐµÄ __DIR__ ³£Á¿£©£º
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º // this is relative to the loaded script's path // it may cause problems when running scripts from different directories require_once('config/database.php'); // this is always relative to this file's path // no matter where it was included from require_once(dirname(__FILE__) . '/config/database.php');ʹÓà __LINE__ ʹµÃµ÷ÊÔ¸üΪÇáËÉ¡£Äã¿ÉÒÔ¸ú×Ùµ½¾ßÌåÐкš£
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º // some code // ... my_debug("some debug message", __LINE__); /* prints Line 4: some debug message */ // some more code // ... my_debug("another debug message", __LINE__); /* prints Line 11: another debug message */ function my_debug($msg, $line) { echo "Line $line: $msg
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ