Home > PHP > 15 methods to boost your PHP based website’s performance

15 methods to boost your PHP based website’s performance

PHP is great for writing quick dynamic stuff for your website. Just a couple of lines of code can be written in 2 mins to insert or retrieve data from db. But with ease there is also some pain… the downside is that each request for a dynamic page can trigger multiple db queries, processing of output, and finally formatting to display on browser. This process can eventually be slow on larger sites or slower servers.

In this article, we’ve put together the list of caching plugins and techniques which can be used to improve your website performance.

  1. Caching output in PHP – Caching of output in PHP is made easier by the use of the output buffering functions built in to PHP 4 and above.
  2. PHP Caching to Speed up Dynamically Generated Sites – Instead of regenerating the page every time, the scripts running this site generate it the first time they’re asked to, then store a copy of what they send back to your browser. The next time a visitor requests the same page, the script will know it’d already generated one recently, and simply send that to the browser without all the hassle of re-running database queries or searches.
  3. Alternative PHP Cache – A free and open opcode cache for PHP. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.
  4. PHP-Cache-Kit – Dramatically speed up your site with this easy-to-use PHP caching kit. A slim little PHP class which allow you to quickly and easily implement module-level caching into your PHP projects.
  5. Unearth PHP Cache Engine – A flexible, easy-to-use system for caching PHP pages. It is really intended to cache a series of parts of a single page independently, each with its own refresh requirements. Caching of this sort can dramatically decrease page rendering time.
  6. PHP Cache Class – A PHP class that caches output generated by PHP files and uses the cached version instead of generating the content again and again. Cache files expire after a specified amount of time.
  7. PHP Accelerator – A plugin PHP Zend engine extension that provides a PHP script cache and is capable of delivering a substantial acceleration of PHP scripts without requiring any script changes, loss of dynamic content, or other application compromises.
  8. gCache – A PHP class that can be used to capture and cache Web page content. It can store cached content in files of a given directory.
  9. Skycache – A free, lightweight, and fast page cache for PHP 4 and PHP 5. Once a dynamic page has been computed, it is stored in a page cache. If a query for the same URL is made afterwards, the content is immediately served from the cache instead of processing the script again. The end result is a significant speedup and a slightly reduced server load.
  10. eAccelerator – A further development of the mmcache PHP accelerator and encoder. It increases the performance of PHP scripts by caching them in a compiled state, so that the overhead of compiling is almost completely eliminated.
  11. PHP FastFileCache – Caches output from dynamic PHP scripts, and stores them in files for fast retrieval under high server load. It supports a global timeout setting for maximum cache age, as well as per-file timeout overrides. It also implements file locking, to prevent data corruption and unnecessary processing.
  12. CacheIt – A PHP class designed to facilitate caching.
  13. Turck MMCache for PHP – A free PHP accelerator, optimizer, encoder, and dynamic content cache. It increases performance of PHP scripts by caching them in a compiled state, so that the overhead of compiling is almost completely eliminated.
  14. TinyButStrong – A template class for PHP that allows you to generate HTML pages using MySQL, PostgreSQL, SQLite in native, and any other databases.
  15. Boost website performance in 5 seconds! – Not exactly caching but simple enough to implement a quick fix.

Did we miss something? Please let us know in the comment area.

Categories: PHP Tags: ,
  1. EllisGL
    February 3rd, 2010 at 01:41 | #1

    Ah, why not name the article “13 Caching Methods for PHP and more”?

  2. po5i
    February 3rd, 2010 at 11:43 | #2

    Agreed.

    I expected to read also about server settings in php.ini or apache. Memory settings, etc.

  3. February 4th, 2010 at 07:54 | #3

    Excelent post. Thanks

  4. February 4th, 2010 at 14:38 | #4

    @EllisGL

    I should have but then again #14 and specially #15 has been simplest and fastest method to cache something that is under heavy load.

  5. February 6th, 2010 at 08:36 | #5

    Yeah we have increase the sites performance since there are lots of considerations like google caffine is coming out. Its really a very nice post.

  6. February 8th, 2010 at 13:37 | #6

    @po5i

    Generally you won’t be able to find a lot of things about server settings or php.ini. PHP is pretty optimized already and many of the settings that PHP has available are more for turning specific features on and off. Architectural considerations are more likely to have a larger impact than configuration tuning.

  7. February 8th, 2010 at 13:48 | #7

    @Kevin
    Someone mentioned to me that PHP runs faster on Lighttpd than on Apache. Being from Zend, what is your observation?

  8. February 8th, 2010 at 16:23 | #8

    @madiga

    I doubt it. Once PHP is running it is generally staying inside of the PHP binary and the web server architecture doesn’t matter as much at that point. Lighttpd generally runs PHP from within FastCGI which is a layer in between the web server and PHP. While I don’t have any specific numbers I would actually expect Lighttpd to run PHP a smidgen slower because of the FastCGI layer. Actual numbers would be beneficial so I will see if I can dig some up.

    What is often done is running PHP inside of Apache, but then taking static content such as images, CSS and JavaScript, and serving those from Lighttpd. What this does is make your website, as a whole, _feel_ faster. That is generally going to be more important than eeking out a few additional ms of performance from PHP.

  9. February 8th, 2010 at 17:09 | #9

    @madiga

    Did some quick testing and saw that they were virtually identical. I used FCGI/PHP/APC for Lighttpd and Zend Server/Apache with a “Hello World” Zend Framework app. Zend Server w/ Apache was 3.9ms per request, Lighttpd w/ FCGI was 4.1ms per request. So, Apache was a little quicker, by 1/5th of a ms.

  10. February 8th, 2010 at 18:16 | #10

    @Kevin

    That’s pretty interesting comparison. The reasoning behind Lighty being faster than Apache is because well it’s lightweight apparently. I wasn’t aware in order to run php, it it utilizes fastCGI. I’m assuming same holds true for Perl.

    I have to check out the Zend Server pkg…I’m guessing that’s a commercial package provided and maintained by Zend which contains apache/php/mysql, does regular updates etc? Wouldn’t mind posting an article about it here.

    Thanks for your info.

  11. February 8th, 2010 at 18:47 | #11

    @madiga

    Yeah, the “lightweight” refers to the connection architecture. After the connection is made, the PHP is identical with regards to execution, except for the SAPI.

    Zend Server is our application server for PHP. You can start at http://www.zend.com/en/products/server/. Generally we try to hook in with whatever server is set up on your machine. IIS for Windows and Apache for Linux/i5. If you have a web server from a supported setup (i.e. RHEL) we will integrate with the installed web server instead of installing our own. We also have a public beta for Zend Server 5.0 with a new feature called Code Tracing which is worth the time to look at. Please let me know if you have any questions.

  12. February 8th, 2010 at 18:51 | #12

    @madiga

    … also, you don’t NEED FastCGI to run PHP, but if you want to run it in any way that resembles useful, from a performance perspective, you would want to.

  13. February 8th, 2010 at 19:38 | #13

    @Kevin

    Thanks. The code tracing feature sounds quite interesting.

  14. February 9th, 2010 at 10:14 | #14

    @Kevin

    Also, to make sure that nobody misunderstands my intention here; these numbers were tested on two un-optimized installations. Rather than showing that Lighttpd or Apache is faster than the other, my intention is to show that from the PHP standpoint they are close enough in terms of performance that performance concerns are relatively minimal. There will likely be much, much lower hanging fruit than any difference between Lighttpd and Apache would show.

  1. February 3rd, 2010 at 00:47 | #1
  2. February 3rd, 2010 at 01:20 | #2
  3. February 3rd, 2010 at 02:14 | #3
  4. February 3rd, 2010 at 02:27 | #4
  5. February 3rd, 2010 at 06:47 | #5
  6. February 3rd, 2010 at 07:32 | #6
  7. February 4th, 2010 at 03:15 | #7
  8. February 4th, 2010 at 06:24 | #8
  9. February 4th, 2010 at 09:40 | #9
  10. February 8th, 2010 at 10:41 | #10
  11. March 20th, 2010 at 22:39 | #11