Hiya, I have now reached the point in my web development life where i now need to be careful how I construct page to allow for minimal CPU load.
My host suspended an account today cos some of my pages were suing too much CPU with the high traffic volume i’m getting these days
The scripts i have are very basic, using flatfiles to store paragraphs of text and part of html code for inclusion to a php page.
My guess is that its the reading/writing of the flatfiles (use flatfile caches to) that is eating up the CPU. IF i’m correct should I convert my flatfile function into MYSQL queries, then write the results into a static html page, and perhaps have a cron function to write new updated pages every few hours?
Does this sound like a plan, or am I going up the wrong path again?
its not high traffic to you big guys, but its high to me hehe. he did suggest moving to a VPS, but of course he would! When i start pulling in more consistent £ then i’ll upgrade for sure.
I will go down the mysql route, and create an option to write to html file, and then my host can compare the performance or each over a period of time.
edit: origianl post should say higher traffic lol!
what about the size of variables? for instance is it ok to have $text = paragraphs and paragraphs of text?
make sure you REALLY need to upgrade.
I had host telling me my sites were using to much CPU, and that I need to upgrade VPS when I barely had any traffic on them. (and they said nothing when i had 10x the traffic for a few months)
You can try to cache your data, I’m sure you have parts of your pages that get generated with an output that does not change.
Its quite hard to help reduce the CPU profile of your scripts without actually seeing the code, You could setup http://www.xdebug.org/ with [URL=“http://kcachegrind.sourceforge.net/html/Home.html”]http://kcachegrind.sourceforge.net/html/Home.html these tools are a great way to fine tune the performance of your scripts/applications by profiling with Xdebug. When configured correctly, Xdebug will output trace files that you can check with kcachegrind or wincachegrind to find potential bottlenecks. There are a number of steps you’ll need to take to setup your environment before you can use these tools - if you’re running Windows, forget it, you will need a *nix flavor of some description.