Your PHP Changes Are Not Showing on Your Joomla Website? Maybe It’s OPCache

Earlier today, we ran into a very weird issue… We were making some changes to a cron PHP file (under the cli folder), but our changes were not taking effect. This was very odd because we were sure that no caching was enabled anywhere on the server, at least so we thought.

What was odd is that if we renamed the file, to something like cron-file-1.php instead of cron-file.php, our changes were taking effect, but only once. So, if we made additional changes, we had to rename the file to cron-file-2.php, cron-file-3.php, cron-file-4.php, and so forth…

A few hours of investigation revealed that the cause of the problem was (unsurprisingly) PHP’s built-in caching system, OPCache, which, to put it simply, translates normal PHP code into machine code and stores it into the server’s memory in order to eliminate the compilation phase each time a PHP file is requested by the web server, which will lead to some performance gain.

So, in short, we just needed to disable OPCache, at least for that particular folder, in order to get our code to refresh.

So, how did we disable OPCache?

We just created a .user.ini file and placed it in the cli folder, and then added the following code to it…

opcache.enable=0

…and that did the trick! The second we created the .user.ini file, the problem was solved. Our PHP changes were taking effect instantly, and we were very exalted!

But isn’t a good idea to leave OPCache enabled?

While we don’t think highly of the advantage that OPCache brings to the performance of a web application, we still believe that any improvement is a good improvement, so it’s a good idea to turn it back on (by removing the above line from the .user.ini file) once you’re done with it. Some claim that the improvement in response time can be as high as 70%, but we cannot confirm this.

So, the next time you make a change to a PHP file, and you don’t see your change taking effect immediately, try disabling OPCache by just adding the above line. If it doesn’t work, or if you need help with the implementation, then please contact us. Our fees are affordable, our work is quick, and we are the Joomla experts!

No comments yet.

Leave a comment