Optimising PHP-FPM and MySQL for High-Concurrency Applications

Introduction

When dozens—or even thousands—of people use a website at the same time, the server needs to juggle all those requests smoothly. This is what we call concurrency. In a PHP/MySQL stack, poor handling of concurrency often shows up as slow page loads, failed transactions, or even complete outages.

Why Concurrency Matters in PHP/MySQL Stacks

PHP-FPM handles incoming requests, while MySQL powers the database queries behind each action. If either gets overwhelmed, the entire application stalls. A single unoptimised setting can become a bottleneck—forcing users to wait in line, much like too few cashiers at a busy store.

At small scale, these issues may not appear. But as traffic grows—think flash sales, peak booking hours, or viral campaigns—every second counts. Tuning PHP-FPM and MySQL for concurrency ensures faster responses, fewer crashes, and a smoother experience for end users.

PHP-FPM Tuning

Set the Correct pm Mode

PHP-FPM controls how it spawns workers with the pm (process manager) setting.

  • Dynamic – best for high-traffic apps; keeps some workers always ready and scales up as load increases.
  • Ondemand – good for lighter or bursty workloads; saves memory by only creating workers when needed.

Tweak max_children and max_requests

  • pm.max_children sets the maximum number of worker processes. Too low = long queues; too high = memory exhaustion. Calculate it by dividing available RAM by the average memory each PHP process consumes.
  • pm.max_requests recycles workers after serving a set number of requests (e.g., 500–1000). This prevents memory leaks from dragging down long-running servers.

Reduce Idle Process Load

Excess idle workers waste memory. Use:

  • pm.min_spare_servers and pm.max_spare_servers (in dynamic mode) to keep just enough idle workers ready.
  • Lower these values on memory-constrained servers, especially when many workers sit idle during off-peak hours.

Optimising these few parameters can make PHP-FPM far more stable under heavy concurrency.

MySQL Optimisation

Increase innodb_buffer_pool_size

This is the most important MySQL setting for performance. The buffer pool is where MySQL caches data and indexes in memory. Setting it too small forces the server to fetch from disk repeatedly—slow under load. A good rule is to allocate 60–70% of available RAM (on a dedicated DB server) to the buffer pool.

Limit Slow Queries

Even with enough memory, poorly written queries can block other requests. Use tools like EXPLAIN to analyse queries and add indexes where needed. Monitor the slow query log to catch inefficient SQL before it becomes a bottleneck.

Use Connection Pooling

Opening a new database connection for every request is expensive. Instead, use a pooling tool (e.g., ProxySQL, PHP’s pdo_mysql with pooling support, or external services) to keep connections open and reuse them. This reduces overhead and helps the database handle spikes in concurrent traffic.

System Monitoring

Use the Right Tools

  • htop – real-time view of CPU and memory usage; helps spot overloaded servers.
  • mysqltuner – gives practical recommendations for MySQL configuration based on workload.
  • PHP-FPM status page (pm_status) – shows active, idle, and queued PHP processes in real time.

Watch Key Metrics

  • Memory & CPU: Ensure PHP workers and MySQL aren’t consuming more than the server can handle.
  • Query times: Track long-running queries; even one bad query can block hundreds of concurrent requests.
  • Request queues: A growing queue in PHP-FPM means you need more workers or further optimisation.

Regular monitoring lets you adjust settings before problems cascade into downtime.

Scaling Tips

Separate App and DB Layers

Running PHP-FPM and MySQL on the same server works for small projects, but at scale it creates competition for memory and CPU. Splitting them onto dedicated servers (or containers) ensures each can use resources fully and makes troubleshooting easier.

Add a Load Balancer for PHP Workers

When one server can’t handle all incoming requests, distribute the load across multiple PHP-FPM servers. A load balancer (e.g., Nginx, HAProxy) spreads traffic evenly, improving responsiveness and providing redundancy if one server fails.

Scaling horizontally—adding more servers instead of overloading one—keeps performance stable as traffic grows.

Conclusion

High-concurrency applications live or die by how well they manage PHP-FPM and MySQL under pressure. Default settings may be fine for a small blog, but they quickly buckle when traffic spikes. By tuning key parameters, monitoring actively, and planning for scale, you build an environment that stays fast and reliable—even under thousands of simultaneous requests.

Production-Ready Checklist

  • Set the right PHP-FPM pm mode (dynamic for high traffic).
  • Calculate and tune pm.max_children based on available RAM.
  • Use pm.max_requests and request_terminate_timeout to keep workers healthy.
  • Allocate 60–70% RAM to innodb_buffer_pool_size.
  • Monitor and fix slow queries; add indexes where needed.
  • Implement database connection pooling.
  • Track system health with htop, mysqltuner, and pm_status.
  • Separate app and DB layers; add load balancer for scaling.

With these steps in place, your PHP/MySQL stack is optimised for concurrency and ready to handle production workloads with confidence.

Ideas to Innovations: Bagful

Cloud Management  Services

Experience seamless Cloud Management with services that prioritize cost efficiency, robust security, advanced automation, and performance optimization. From optimizing multi-cloud, hybrid setups, and containerized applications to ensuring peak scalability and reliability, we handle every aspect of your cloud infrastructure. With cutting-edge tools and expert support, we empower businesses to innovate, scale, and thrive in a competitive landscape.

List of Cloud Management services provided by Bagful

Infrastructure as a Code (IaC) Services

Enhance your cloud infrastructure with our expert Infrastructure as Code (IaC) services, enabling automated provisioning, seamless multi-cloud management, and scalable deployments. Utilize leading tools like Terraform, Ansible, and Kubernetes to boost efficiency, reduce costs, and ensure robust security. Our tailored IaC solutions empower your business to achieve agility, reliability, and compliance in today’s dynamic digital landscape.

List of Infrastructure as a Code services provided by Bagful

Messaging and Notification Services

From startups to enterprises, our platform streamlines messaging and notification processes, enabling you to focus on what truly matters—building lasting connections. With unmatched reliability, flexibility, and real-time engagement, our services are designed to align perfectly with your business objectives. Bagful Messaging and Notification Services empower you to deliver the right message, at the right time, through the right channel.

List of messaging and notification services provided by Bagful

Identity and Access Management Services

Experience comprehensive Identity and Access Management with our Microservices-driven IAM as a Service. We provide secure user authentication, seamless Single Sign-On (SSO), Multi-Factor Authentication (MFA), privilege management, and cloud-native access control. Simplify identity management while ensuring robust protection for your applications and resources.

List of IAM and Access Management  services provided by Bagful

Storage Services

At Bagful, we offer a full spectrum of Cloud Storage Solutions tailored to your business needs, from high-performance block and object storage to scalable file systems and cost-effective archival options. Whether you need private, hybrid, or multi-cloud storage, our services ensure security, scalability, and seamless accessibility. Simplify your data management while optimizing costs with our reliable and innovative storage solutions.

List of monitoring and logging services provided by Bagful

Database Services

We provide fully managed and Unmanaged database services integrated with microservices in our cloud environment. From relational and NoSQL databases to in-memory and time-series solutions, our offerings ensure seamless scalability, reliability, and performance. Built for modern cloud-native architectures, our services enable efficient data operations tailored to your business needs.

List of monitoring and logging services provided by Bagful

Load Balancers and API Gateway

We provide streamlined deployment of Load Balancer and API Gateway services tailored for microservices. Our solution ensures optimal scalability, secure traffic distribution, and simplified API management, all without requiring specialized expertise. Designed to adapt seamlessly as your infrastructure evolves, it empowers you to focus on delivering exceptional user experiences.

List of Load Balancers and API Gateway  services provided by Bagful

Monitoring and Logging​

We offer single-click deployment of Monitoring Services such as Telemetry and Prometheus, tailored for microservices in isolated environments. Our solution scales effortlessly as your monitoring needs grow with additional resources and applications, ensuring optimal performance. With an intuitive selection and configuration process, our services eliminate the need for specialized expertise, simplifying the implementation of robust monitoring systems.

List of monitoring and logging services provided by Bagful

Container Orchestration

Our Containerization Platform as a Service empowers businesses with agile development, streamlined deployments, and efficient scaling through portable, consistent environments. Designed to optimize resource utilization and support microservices architectures, it drives innovation, operational efficiency, and cost-effectiveness.

Below is a list of services which we provide as a service

;