
By Andreas Grabner | Article Rating: |
|
October 6, 2014 09:15 AM EDT | Reads: |
13,745 |

Are you developing or hosting PHP applications? Are you doing performance sanity checks along your delivery pipeline? No? Not Yet? Then start with a quick check. It only takes 15 minutes and it really pays off. As a developer you can improve your code, and as somebody responsible for your build pipeline you can automate these checks and enforce additional quality gates. And as a PHP Hosting company / group you will be able optimize your deployment and run more of these apps and sustain more load on the same infrastructure.
Just like Java, .NET, and Ruby type applications, the top performance bottlenecks are fairly easy to spot and fixing them improves end user performance and saves compute power for your servers.
Here is what we discovered when analyzing our own Moodle-based educational platform using the 15 Day Free Trial of dynaTrace:
- High PHP Compilation Time: Our App spends up to 66% of the time in compilation
- Bad database access patterns: Some of our web requests execute up to 592 SQL requests
- Inefficient PHP coding: Rendering HTML lists in result pages takes 5+ seconds
If you are interested in learning more about PHP Performance, be sure to check these posts out: Basic PHP Performance Tips (Google Dev) and 5 Things to Improve PHP Performance (DZone).
#1: PHP Compilation Time
In a standard PHP installation every web request processed by the PHP engine will be compiled. The compiled code will not be cached which means PHP needs to re-compile the same code when the next request comes in. In our system we saw compilation time spikes of up to 66% of the total execution time:
Many of our requests spend a lot of time in compiling complex PHP files. Optimizing these files will improve overall response time
It also pays off to analyze PHP Compilation Time long term. In our case we noticed that a new deployment let the Compilation Time Contribution jump to twice of what it was before. Having this insight allows you to review your code changes as well as think off using PHP Compilation Caching using PHP Accelerators.
Warning Signal for PHP Monitoring: A change in our deployment in combination with more traffic on April 3rd caused our PHP Compilation Time contribution to double
Key Takeaways
- Developers: Analyze compilation time of your PHP code to identify complex coding early on
- Testers: Watch out for PHP Compilation Time changes from build to build to identify regressions early on
- Operations: Use PHP Accelerators as part of your PHP deployment in order to speed up overall PHP performance
#2: Bad database access patterns
Bad database access patterns are a common theme in the blog posts we write, mainly focusing on Java and .NET Enterprise Apps. Check out DB Access Patterns Gone Wild or When It Really Is The DB To Blame.
PHP Applications face the same problems. Watch out for the N+1 Query Problem; executing the same SQL multiple times per request or requesting data with multiple SQLs instead of optimizing a single SELECT statement:
Instead of specifying a proper IN-Clause the same SQL is executed hundreds of times with different WHERE-Clause causing unnecessary DB Roundtrips
Executing the exact same SQL up to 95 times is a sign for caching the data instead of requesting it over and over again from the database
To spot these problematic access patterns in production simply monitor the number of database executions and compare them with the incoming transactions as well as total database time as shown in the following chart:
In a production environment you do not want to see many spikes in database execution count and time that don't correlate to incoming load. That would indicate a data-driven performance/architectural problem
Key takeaways
- Developers: Analyze which statements get really executed by your code as well as any third-party libraries you use to access code
- Database Engineers: Watch out for SQL Executions from PHP and sit down with engineers to optimize their SQL queries in their code. Provide guidance on SQL coding or stored procedures instead of having them execute hundreds of SELECT queries
- Testers: When executing load tests watch out for any load-related DB access patterns. Which "static" data is queried all the time and might be better off by caching it in the application?
- Operations: Monitor spikes in # of SQL Executions and whether that relates to a data-driven problem such as a user using a very exotic search term that results in too many SQL queries
For tip #3, and for further insight, click here for the full article
Published October 6, 2014 Reads 13,745
Copyright © 2014 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Andreas Grabner
Andreas Grabner has been helping companies improve their application performance for 15+ years. He is a regular contributor within Web Performance and DevOps communities and a prolific speaker at user groups and conferences around the world. Reach him at @grabnerandi
![]() Dec. 31, 2017 12:00 PM EST Reads: 1,500 |
By Pat Romanski ![]() Dec. 30, 2017 11:00 AM EST Reads: 1,367 |
By Pat Romanski ![]() Dec. 30, 2017 08:30 AM EST Reads: 14,196 |
By Liz McMillan ![]() Dec. 29, 2017 12:00 PM EST Reads: 2,543 |
By Liz McMillan ![]() Dec. 29, 2017 08:00 AM EST Reads: 2,593 |
By Pat Romanski ![]() Dec. 28, 2017 02:00 PM EST Reads: 3,390 |
By Liz McMillan ![]() Dec. 24, 2017 01:45 PM EST Reads: 1,568 |
By Elizabeth White ![]() Dec. 23, 2017 10:00 AM EST Reads: 1,459 |
By Elizabeth White ![]() Dec. 22, 2017 11:00 AM EST Reads: 1,226 |
By Elizabeth White ![]() Dec. 18, 2017 03:45 PM EST Reads: 2,590 |
By Elizabeth White ![]() Dec. 18, 2017 01:30 PM EST Reads: 2,574 |
By Elizabeth White ![]() Dec. 18, 2017 01:00 PM EST Reads: 4,376 |
By Liz McMillan ![]() Dec. 17, 2017 04:00 PM EST Reads: 1,571 |
By Pat Romanski ![]() Dec. 17, 2017 02:00 PM EST Reads: 1,650 |
By Elizabeth White ![]() Dec. 17, 2017 10:00 AM EST Reads: 1,720 |
By Liz McMillan ![]() Dec. 15, 2017 11:00 AM EST Reads: 2,569 |
By Elizabeth White ![]() Dec. 14, 2017 04:00 PM EST Reads: 1,700 |
By Liz McMillan ![]() Dec. 14, 2017 11:45 AM EST Reads: 1,768 |
By Elizabeth White ![]() Dec. 14, 2017 11:00 AM EST Reads: 1,766 |
By Pat Romanski ![]() Dec. 13, 2017 02:00 PM EST Reads: 1,512 |