了半天居然没找到问题在哪里,一咬牙,写了个性能和负载的记录工具,再出事我可有记录了-,-||
备注:只能在linux下用。
- < ?php
- date_default_timezone_set('Asia/Shanghai');
- define('SLEEPTIME',10); //10秒记录一次
- $memfile = "/proc/meminfo";
- $loadfile = "/proc/loadavg";
- $logfile = sprintf("/var/www/html/log/%s.log",date('Y-m-d'));
- while(1)
- {
- $log = getload();
- $log .= getmem();
- $log .= mymem();
- $log .= "/n/r".date("Y-m-d H:i:s");
- $log .= "/n/r/n/r";
- $handle = fopen($logfile,'a');
- fwrite($handle,$log);
- fclose($handle);
- sleep(SLEEPTIME);
- }
- function getload() //获得负载
- {
- global $loadfile;
- return file_get_contents($loadfile);
- }
- function getmem() //获得内存占用
- {
- global $memfile;
- $mem = file($memfile);
- return $mem[0];
- }
- function mymem() //程序本身内存占用
- {
- $pid = getmypid();
- exec("ps -eo%mem,rss,pid | grep $pid", $output);
- $output = explode(" ", $output[0]);
- return $output[1] * 1024;
- }
- ?>