如何找到耗费CPU资源的php程序?

fish01 2006-03-22 10:19:57
在linux下
用top经常会看到占用CPU资源99.9%的php程序

20627 apache 16 0 74484 6292 4136 S 99.9 0.1 1:50.44 /usr/local/apache2/bin/httpd -k sta

一直要达到max_execution_time 120秒才消失

有什么办法找到具体运行的是哪个php代码吗?

非常感谢!!
...全文
410 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ewangqingshen 2006-03-25
  • 打赏
  • 举报
回复
访问人数多,数据量大,都是原因
fish01 2006-03-25
  • 打赏
  • 举报
回复
也不是每天都会出现,就是在某些特定条件下...狂占CPU(2-3个99.9%) 狂占MEM(几百M-1.xG)

因数据不断的变化,所以没法用静态html文件

用time.php几天后发现它计算的时间是:

PHP程序处理时间+传输到客户端的时间,很难判断
于是想读取系统的CPU MEM资源状态

<?
$u=getrusage();
$o=implode("<br>",$u);

echo $o;
?>
得出:
0
0
0
0
0
0
0
212
0
0
26
0
0
3999
0
999
00000

但不知如何解释这些值的含义






siton 2006-03-25
  • 打赏
  • 举报
回复
建议采用生成静态页面的技术。PHP耗CPU,APACHE耗内存,这是很正常的除非你的站访问的人而后年少。
fish01 2006-03-25
  • 打赏
  • 举报
回复
就是不知到什么时候会发生 ..
访问量每个时段/每天都比较恒定,没有大起大落的状况

gu1dai 2006-03-25
  • 打赏
  • 举报
回复
某些特定条件?哪些条件?

Fibona 2006-03-24
  • 打赏
  • 举报
回复
看看是那一个页面,然后一句句屏蔽,看也行的。
一般就是数据库,死循环等方面。
fish01 2006-03-24
  • 打赏
  • 举报
回复
1.Apache log繁杂很难看出端倪
2.gu1dai(异域苍穹.百年飞行) 的方法不错,简单易行,参考后写下自己的time.php

<?
//time.php
if($time_begin==0){
$time_begin=substr(microtime(),0,4)+substr(microtime(),-3);
$time_used=".";
}else{
$time_end=substr(microtime(),0,4)+substr(microtime(),-3);
$time_used=$time_end-$time_begin;
}

$time=date('Ymd[H:i:s]');

$phpself=$_SERVER[PHP_SELF];

$str="$time\t$time_used\t$phpself\r\n";
$fp=fopen ("d:/server/www/time.txt","ab");
fwrite($fp,$str."\r\n");
fclose($fp );

/*
配置php.ini
auto_prepend_file=time.php
auto_append_file=time.php
*/

?>

3.Xdebug 很强大,好复杂,没调通,继续研究
yunfeifan 2006-03-23
  • 打赏
  • 举报
回复
那你看看你的apache log ,可以看到你现在跑得什么程序
fish01 2006-03-23
  • 打赏
  • 举报
回复
请高手指点啊
blue2004 2006-03-23
  • 打赏
  • 举报
回复
用 xdebug
www.xdebug.org


FUNCTIONALITY

The Xdebug extension helps you debugging your script by providing a lot of valuable debug information. The debug information that Xdebug can provide includes the following:

stack and function traces in error messages with:
full parameter display for user defined functions
function name, file name and line indications
support for member functions
memory allocation
protection for infinite recursions

Xdebug also provides:

profiling information for PHP scripts
script execution analysis
capabilities to debug your scripts interactively with a debug client
iasky 2006-03-23
  • 打赏
  • 举报
回复
apache的日志
gu1dai 2006-03-23
  • 打赏
  • 举报
回复
http://gudai.cnblogs.com/articles/354557.html
uuq 2006-03-23
  • 打赏
  • 举报
回复
楼上说了多看下apache 日志

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧