Back to Home

Diagnosing and Solving Performance Issues in a Monolithic PHP App

If you’ve deployed a monolithic PHP application with a MySQL database and you notice that the performance drops significantly when around 80 users access it simultaneously, you're not alone. Performance bottlenecks in monolithic apps are common, but identifying the root cause can be tricky due to the number of moving parts involved. Below, we’ll walk through common causes of performance issues in PHP apps and provide actionable steps to resolve each one.


1. Inefficient Database Queries

When your app slows down under load, one of the first places to check is the database. Slow or inefficient queries can bottleneck your entire application.

Tools: MySQL slow query log, EXPLAIN, SHOW INDEXES


2. Lack of Database Connection Pooling

Opening a new database connection for every user request can become expensive, especially under heavy load.

Tools: MySQL connection settings, ProxySQL, mysqli::persistent


3. PHP Session Handling Bottlenecks

By default, PHP stores sessions on the file system, which can cause session lock contention when multiple requests need to access or modify the same session data.

Tools: Redis, Memcached, PHP’s session_set_save_handler()


4. I/O Bottlenecks

High disk I/O can slow down your app, particularly if your MySQL database is frequently writing to disk or if your server is logging heavily.

Tools: iostat, iotop, MySQL settings (innodb_buffer_pool_size)


5. Apache Configuration Issues

Apache’s default configuration might not be optimized for handling large amounts of traffic, leading to slowdowns as user numbers increase.

Tools: Apache configuration (apache2.conf or /etc/httpd/conf/httpd.conf)


6. Lack of Caching

Without caching, your server performs the same expensive operations repeatedly, even for data that doesn’t change between requests.

Tools: Redis, Memcached, OPcache


7. PHP Performance (Opcache)

If PHP is not caching its compiled scripts, it will recompile them on every request, which is highly inefficient.

Tools: PHP Opcache, php.ini (opcache.memory_consumption)


8. High Memory Usage

Excessive memory usage can cause your server to slow down, particularly if it starts swapping data to disk.

Tools: htop, vmstat, free -m


9. Concurrency and Scalability Issues

Your application code may not be optimized for handling many concurrent users, leading to race conditions or other blocking issues.

Tools: Code refactoring, MySQL transactions, locking mechanisms


10. Network Latency

Network issues between your app and its database or between the app and users can slow down response times.

Tools: ping, traceroute, Wireshark, CDN (e.g., Cloudflare)


11. Lack of Monitoring

Without proper monitoring, it’s hard to track down what’s causing performance issues, making troubleshooting much more difficult.

Tools: New Relic, Prometheus, Grafana


Conclusion

By systematically addressing these common performance bottlenecks, you can significantly improve the speed and responsiveness of your monolithic PHP application. Start by monitoring key metrics and using the right tools to diagnose specific issues, then apply optimizations step by step. With proper tuning, your app will be ready to handle more users without sacrificing performance.

Happy coding!