This is part 5 of a 6 part series looking at the some of the wonderful features of PHP 5.5 and why it might remain a dominate web language for the future. This series was originally written for the Software Developer’s Journal.
One of the main criticisms of PHP has always been “it is sloooowwww” or “slower than ______” (fill in the blank with some other trendy language). While sometimes this is the case because of the language, it is often more the case from bad programming. Which in any language could slow it down. But to help with this, the PHP community has decided to implement a caching mechanism called OPcache. This change will allow some dynamically generated pages act more static by compiling the script and caching it. We talk about it more in this part of the series below.
We all know how important it is for the web to be fast and responsive. Newly bound into PHP 5.5 is OPcache (aka Zend OPcache) which allows you to easily compile and cache PHP scripts to then be rendered on a moment’s notice. This is perfect for scripts that you know are going to end up with the same result no matter how many times they are run. This is a new feature designed to help with the pillar of performance we mentioned earlier.
As with any caching mechanism it is important that you find the right balance between serving up a fresh copy of a script versus a cached one. An instance where OPcache could be really useful is for projects like a historical stock price ticker script.
Why is this huge? Well, it means that you can compile complex or slow scripts, stuff them in cache and serve them up in milliseconds. The end result is that your site is much faster and more responsive right where it counts. Faster sites mean a better experience for the end user and that could lead to a happier, and perhaps more profitable, future buyer.
Where would this be a hindrance? Well, if the page is truly dynamic, where each time it is requested it is likely to be different, then you wouldn’t want to cache it. Otherwise the info you are displaying may be stale and would have the opposite effect on the user. Who wants to visit a stale site and see a ticker which is not showing accurate information?
To help guide you on the best way to use this, I recommend you read up about the advantages of caching web graphics or handling browser caches. The advantages to caching scripts are very similar.
In our last part of the series we talk a bit about where PHP might go next. We briefly talk about a couple proposal features mentioned and I offer a few thoughts on them.
Thanks again for reading! 🙂