Three Obstacles to Perfect PHP Performance Under Continuous Delivery

CycleIf you are building PHP apps and spotted their performance is not very outstanding, you should start doing some sanity checks for performance along the delivery pipeline. A quick performance check will take you 15 minutes and will pay off well after release. Such checks will help developers improve their code, project managers will be able to enforce some additional quality gates by automating these checks, and a PHP hosting company will benefit from optimizing such a deployment to run more apps and sustain even more load on its infrastructure.

The major bottlenecks in performance, just like with .NET, Ruby and Java, are pretty easily spotted while their fixing saves your servers’ compute power and boosts end user performance considerably.

Among the things you should look for during performance checks, are the major three:

  1. Poor Database Access Patterns

The issue of bad access patterns is a common subject of many blog posts, mostly in .NET and Java enterprise apps. PHP developers are familiar with this problem, too. In order to detect such problematic patterns in production you need to just monitor the database executions’ number and compare those with incoming transactions and the total database time. Thus, the main thing PHP developers should do to eliminate poor database access patterns is to analyze which statements really get executed by their code along with all third party libraries used to access PHP code.

  1. PHP Compilation Time

You should also analyze your PHP code’s compilation time and identify complex coding right at the beginning. A regular PHP installation suggests that every web request which is processed by PHP engine is compiled. This compiled code is not cached, so PHP has to recompile one and the same code as a new request comes in. Sometimes compilation time spikes can reach 65% of your total execution time. Long-term PHP Compilation Time will also pay off if analyzed. For example, a new deployment may let Compilation Time Contribution double compared to its earlier value. Given this insight, you should start reviewing your code modifications and consider using PHP Accelerators and PHP Compilation Caching.

  1. Inefficient Coding

Another big hotspot is rendering the content into HTML. If you look at your PHP Execution time hotspots, you’ll probably reveal that some methods take an overly long execution time while rendering certain page aspects. That’s why one you spot a PHP file or method, make sure to check out their execution time variance because a huge variance will likely mean some data-driven performance problems. Monitoring the load impact on the response time is a good habit when in the production environment. For a takeaway, it’s essential to profile your code during the development. Think of what you are rendering to HTML and if all that data is actually needed to be displayed on every page output.

Watch out for the hotspots described above - and you will for sure find a few SQL queries that can be eliminated or some code to be optimized both in terms of execution time and compilation.