Interview question
What is connection pooling and does PHP support it natively? Connection pooling क्या है और क्या PHP इसे natively support करता है?
Answer
Connection pooling reuses a set of open database connections across requests instead of opening/closing one per request, reducing overhead.
| Aspect | Detail |
|---|---|
| Native PHP support | No - traditional PHP-FPM creates a new connection per request |
| Persistent connections | PDO::ATTR_PERSISTENT can reuse connections, but has caveats |
| Common solutions | ProxySQL, MySQL Router, application-level pooling in long-running processes (Swoole, RoadRunner) |
$pdo = new PDO($dsn, $user, $pass, [
PDO::ATTR_PERSISTENT => true
]);Persistent connections can cause issues with transaction state leaking between requests, so they should be used carefully and tested thoroughly.
Connection pooling requests के बीच खुले database connections को reuse करता है, हर request पर नया connection नहीं खोलता।
| पहलू | विवरण |
|---|---|
| Native PHP support | नहीं - PHP-FPM हर request पर नया connection बनाता है |
| Persistent connections | PDO::ATTR_PERSISTENT reuse कर सकता है, पर सावधानी चाहिए |
| Common solutions | ProxySQL, MySQL Router, Swoole/RoadRunner जैसे long-running processes |
$pdo = new PDO($dsn, $user, $pass, [
PDO::ATTR_PERSISTENT => true
]);Was this answer clear?