Forum Moderators: coopster

Message Too Old, No Replies

Too CPU Intensive

What can I do?

         

BlueScreen

6:21 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



A PHP script I have on my website which is pretty simple, basically comprising of a few includes (header, footer) and a single database query has been criticised by my host for being too CPU intensive and must be disabled.

I run the script locally on my machine under apache and watch the CPU usage and it's fine.

Is there anything I can do to see if my script really is as bad as my host seems to reckon, could my host be mistaken it's my script that's at fault and pushing the memory and CPU up, or what can I do?

Thanks

lorax

6:35 pm on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Run some benchmarks of your own and ask to see theirs. If the numbers don't match then you have something to discuss with them.

BlueScreen

8:37 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



Thanks for the reply.

However, I'm not exactly sure how to proceed benchmark wise. I dont have a proper webserver, and my local server is only Windows XP with just me using it, a bit different to a unix based server with loads of people accessing the site.

coopster

9:17 pm on Nov 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, BlueScreen.

One thing to watch out for is using an include() in a loop when you should be using a function. It eats memory. One way to help you monitor where and when you are having issues is a simple plug-in of the PHP memory_get_usage [php.net] function. Follow the link for usage examples.

freeflight2

9:35 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



any chance to install mmcache? (or have host install it), also dedicated servers go for $39/mo... then you'd be the boss!

BlueScreen

10:51 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



Thankyou for the replies and the welcome :)

I tried creating a test file with my template and the memory_get_usage function but alas that didnt work ( Fatal error: Call to undefined function: memory_get_usage() )

Are there any other ways of seeing just how bad my script apparently is?

Sorry if I'm missing something obvious, I apreciate the help.

coopster

10:55 pm on Nov 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




memory_get_usage() will only be defined if your PHP is compiled with the --enable-memory-limit configuration option.

I would follow lorax's advice here. If you don't have a test server setup, you may want to so you can compile in the functions and features that you want to use. Benchmark on your system to see what and where issues may be.

BlueScreen

11:14 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



Unfortunately, all the servers I do have access to (well, limited access) do not have it enabled, and I only have a windows machine to develop on, so I can't do it here either, so I'm rather stuck as to finding some way I can test using that function :( - is there no other way?

coopster

12:18 am on Nov 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I see you haven't visited our PHP Forum Library [webmasterworld.com] yet ;)

Installing a new web server: Apache2, PHP5, MySQL4 and PHPmyAdmin [webmasterworld.com]

Forse

8:12 am on Nov 12, 2004 (gmt 0)

10+ Year Member



Why not use caching? That way you'll display static content 99% of the time. You should see cache_lite at pear.php.net