1

Topic: Optimization tips?

Yesterday I've received an error that I went over my CPU quota and last night the server at my hosting provider went down.

I've stitched several PHP scripts together: PunBB, sBlog, SimplePie. I'm very sceptical a few generic php scripts could have brought the server down. Anyway I haven't really touched the scripts themselves, mostly just html and css stuff. And my sites aren't even really live yet.

What can I do to optimize my site? How can I make sure it's using caching etc. whereever possible?

Re: Optimization tips?

Ask your host what specific scripts were going over

3 (edited by Peter 2007-03-19 18:03)

Re: Optimization tips?

My host was very vague and unhelpfull. They directed me to php.net. They're probably overloading their servers. I'm considering just moving to another host before I "go live" with my sites.

I've noticed the site becomes a lot faster when I take out the SimplePie newsfeeds, but I haven't found any complaints online that SimplePie takes too much CPU.

I'm not desperate for a solution on this one. I thought this was a usefull thread to start in general: If you're stitching php scripts together, what should you watch out for to make sure the site doesn't get too heavy on the CPU?

Re: Optimization tips?

Peter wrote:

.. I'm very sceptical a few generic php scripts could have brought the server down.

Hah! I once worked with a young web programmer who, while he was learning PHP, regularly sent a quad-CPU web server to 100% CPU utilisation with just the simplest chunks of code. I had to spend a lot of time watching over the apps he was working on, and his access to our production web server at the time.

Aside from simple bad code, the main issue with shared hosts running PHP web apps is usually MySQL related:  too many open connections, too many simultaneous queries etc. MySQL can be such a pig. Minimise any queries your PHP app generates - via caching or turning off bells and whistles in your app (even in PunBB) - and you generally won't go far wrong.

It is interesting to watch the output of the 'top' command on a shared host with lots of users. Sure MySQL is there at the top of the CPU pile a lot, and PHP too less frequently, but both are regularly outdone by spamd (SpamAssassin) and exim (SMTP service) grabbing a LOT of CPU a LOT of the time.

Your host better be certain that PHP is the culprit in your CPU woes - it usually has a lot of competition for CPU on most shared servers.

5 (edited by Peter 2007-03-23 22:39)

Re: Optimization tips?

I've tried to remove or bypass templating engines from the php scripts in my site and replace it with my own lean html/css. I now worry that I unwittingly removed caching. How can I make sure pages are cached where possible?

I also found this here:

The performance of PHP can be increased to 500% by using caching [benchmarks]. So why is caching not build into PHP? Because Zend, the maker of PHP is selling its own Zend Accelerator and of course, they don't want to cannibalize on there own commercial products.

But there is an alternative: APC.

Anyone have experience with APC or know how to use it?

I'm now studying this: Caching with PHP Cache_Lite...

Re: Optimization tips?

PHP caches = good.

You might want to look at this benchmarks page if you are exploring PHP caches:

http://itst.net/wp-content/uploads/2006 … eview.html

Xcache is the latest and greatest open-source PHP cache, and seemingly the most up-to-date and well supported. It's what all the vBulletin kiddies are using nowadays to eke the most performance out of their hosting accounts.

Of those on that list, I've only used eAccelerator (installed in a VPS environment as a RPM = easy, so far trouble free).

You may also want to look at a simple PHP cache called jpcache - http://www.jpcache.com - as well. Unlike some of the others,  jpcache is relatively simple to set up and doesn't require the deeper level of system access to install that things like APC and eAccelerator do.

As a general guide to optimizing MySQL/PHP apps, the following is also a good reference I always point people to, even though it is focussed on the Typo 3 CMS.

http://typo3.org/development/articles/t … rformance/

The page on PHP tuning at:

http://typo3.org/development/articles/t … ce/page/4/

illustrates very well the virtues of using a PHP cache.

FYI

7

Re: Optimization tips?

Thanks Sirena! smile

JPcache looks easy to use. That's a great starting point. I'll try that when I have time and will report back...

Re: Optimization tips?

Peter wrote:

Thanks Sirena! smile

JPcache looks easy to use. That's a great starting point. I'll try that when I have time and will report back...

No problems. I have successfully run jpcache for over 18 months on a site on a shared hosting account (PHP4) with no problems. It was indeed effective in speeding up a CMS I needed to use, since the web host didn't offer support for any other PHP cache. That site is now dis-continued, but if I needed to I would use jpcache again.

I haven't tried it with punBB though.

9 (edited by Peter 2007-06-16 00:21)

Re: Optimization tips?

I've tried jpcache. It was easy to install and seemed to work, but it messed up certain special characters, like ', and MSIE suddenly couldn't show one page at all. The problems occurred in simplepie newsfeeds.

Any idea how to fix these problems? Which alternatives to jpchache could I try next?

10

Re: Optimization tips?

Any cache may cause problems with dynamic services like RSS feeds, I guess. Caches love relatively 'slow moving' pages, not pages that need to show changes all the time.

Anyway, clear your jpcache cache directory on your server of any old previously generated cache files, clear your browser cache, and try again.

Re those IE errors - perhaps have a look at your settings for jpcache too - you might want to check that your settings for output compression aren't conflicting with something that for example Apache may also be trying to do - ie jpcache may be trying to do compression whilst so too may be Apache. IE supports receiving GZIP compressed content very well, but not if it is mangled. Set the compression level to the lower end of the scale and see if that works better.

You also face the issue when using a php app like PunBB (which does come caching of its own) with jpcache that you may see caching upon caching, the results of which may not be OK. Wherever possible, I suggest always ensuring that just one caching/compression tool is at work.

But I am sure with just a bit of tuning, jpcache will probably settle down and start to work reliably.

In terms of other caches, as an alternative maybe check out xcache - http://xcache.lighttpd.net/

A guide to installing it is here:

http://www.ibm.com/developerworks/libra … fastapps1/

It seems on the way to becoming the cache of choice for a lot of PHP folks, and it certainly is more actively supported than jpcache smile

11

Re: Optimization tips?

Thanks again for the suggestions Sirena!

xcache looks interesting, but my hosting provider has introduced some caching system as well. Have to find time to look into this...