Welcome to WebmasterWorld Guest from 23.20.8.182

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Script increase server load, what to do?

...seeing stuck httpd requests using top command

     
10:53 am on Sep 21, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 3, 2003
posts:961
votes: 0


Hi,

I have built a php script and am using it on my apache server (php version 4 and red hat linux).

The problem that I am facing is that whenever I use the "top" command via ssh on my server, it shows a stuck httpd request due to these php scripts. The request remains stuck for an unforeseen time, increases memory usage and thus increases server load and processing power. Not just 1, there are several such httpd requests running for a very long time and I could say that they terminate only when I do a apache restart.

I have even tried using mysql_free_results, but even that does not seem to work. Any tips on how do I go about debugging this problem.

Thanks!

11:27 am on Sept 21, 2007 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


How long do your scripts take to execute? It sounds to me like something's not finishing.
11:47 am on Sept 21, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 3, 2003
posts:961
votes: 0


the scripts load within seconds. There does not seem to be a problem with the script loading. In fact if there are 100 different requests to this scripts, they all load fast and not all of them get stuck in the memory. Out of these, I can say that around 1% of the scripts may be getting stuck.
11:51 am on Sept 21, 2007 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


First thing I'd do is to upgrade PHP to 5.1 at the minimum. Then, check that your apache is pretty recent.

Next, try to start debugging actual script execution times.

At the top:
$time=time();

As the last two lines:
$duration=time()-$time;
if ($duration>5) error_log("Long running script - took $duration sections");

You should then be able to view your error_log and see exactly how long the slow scripts are taking. From there, try to work backwards ... error_log $_GET arguments, user IDs, etc. until you find out what is special about these particular executions.