Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Modern PHP 8.x & Internals 8-10 Years (Tech Lead) Hard Production Scenario

Explain the difference between `Pdo` connection pooling vs persistent connections (`PDO::ATTR_PERSISTENT`) in PHP-FPM.

Real-World Scenario / Incident Description

Under 5,000 req/sec, MySQL threw "Too many connections" (Error 1040) while PHP-FPM was configured with `PDO::ATTR_PERSISTENT => true`.

692 views • Updated 1 month ago

The Persistent Connection Danger in PHP-FPM

With PDO::ATTR_PERSISTENT, each PHP-FPM worker process keeps its own persistent database connection open even after the request terminates.

  • If you have 500 PHP-FPM workers across 4 web servers, that equals 2,000 persistent idle database connections.
  • Solution: Use dedicated external connection poolers (like ProxySQL for MySQL or PgBouncer for PostgreSQL) rather than in-process persistent PDO connections.
Related Concepts: #PDO #Persistent Connections #Connection Pooling #MySQL