What causes PHP5 to use lots of CPU?


I had to switch from PHP4 to PHP5 (CGI mode) and after switching, DH support contacted me and notified me that my account uses LOTS of CPU. They have set up a resources log that shows what process takes how much CPU and indeed PHP5.CGI is the problem. I have procceces that take 3 seconds of CPU up to 7.5 seconds.

DH support cannot tell me what PHP script causes the problem and they cannot tell me what could have gone wrong by switching from PHP4 to PHP5 (CGI). (Actually, I regret to say that their handling of this issue is below their very high standard.)

I am not using anything special. Mostly accessing text files or querying small MySql tables.

Does anyone here knows what functions or classes or whatever can cause this problem? Is there anywhere a list of things that can go wrong with switching from PHP4 to PHP5 (CGI)?

Is there a way to log the CPU usage of a PHP5 script?


Hanan Cohen

It only shows lines like this:

hananc 3.34 cpu 3680k mem 0 io php5.cgi

php.cgi 2088.0600 98.143% 8.700% 12970 0.161

that looks high to me…what can I do to fix it?

I’m using php4 (not “as cgi”)

PHP as CGI (regretfully) will not show you the file being accessed.

So uhhhh, fall back to PHP4 as CGI or PHP4 as an apache module are your only options.

May I ask why you upgraded to PHP5?

You know… all I get is a directory listing.

I’ve never been able to get any script results.

you have to click on the report you want to view. the one ending in .0 is the one for that day. .1 is yesterday, .2 the day before…


If that log has the date in it somewhere - and I really hope it does! - then write a prepended PHP script that logs the date and the script name being executed and compare the two.

There must be a better way (just looking to see what PHP provides) but it’ll probably require a custom PHP build.

[quote]you have to click on the report you want to view. the one ending in .0 is the one for that day. .1 is yesterday, .2 the day before…
OK… it seems like I was just having an attack of the stupids, or something like that.

I always had the mental image of there being a summary page as the default index when you pointed a browser at that directory.

I already have a cron job copy the most recent daily file to my own viewer page.

Seems like it’s time I wrote a script to display the data in a bar graph, since I already found a semi-decent PHP graphing library.