Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Usually, no. For ordinary PDO and MySQLi connections, PHP releases the connection automatically when the script ends. Close it explicitly after the last database operation only when you know it will not be used again and the script still has substantial non-database work to do. Persistent connections are different: they are retained for reuse rather than closed at the end of each script.
What happens to an ordinary connection at script end?
For PDO, the connection stays active for the lifetime of its PDO object. The PHP Manual says, “If you don’t do this explicitly, PHP will automatically close the connection when your script ends.” In practice, that means you can generally let normal script cleanup release an ordinary connection instead of adding a close operation solely to satisfy a rule.
MySQLi connections are also released automatically at script end. Explicit closure is optional; the PHP Manual describes it as a good idea when database work is complete and substantial processing remains afterward. PHP Manual: PDO connections · PHP Manual: MySQLi close
When should you close it explicitly?
Close an ordinary connection once all database work using it is finished if the script will continue doing significant work that does not need the database. Releasing it then can avoid keeping the connection open unnecessarily during that remaining work. This is a conditional lifecycle choice, not a requirement for every script or a guaranteed performance improvement.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
In PHP, PDO’s connection is released when its object is destroyed. Setting a variable to null can release the object only if no other references keep it alive; statement objects or other references may still retain the connection. For MySQLi, use the connection’s close() method when you want to close it early.
When is it safer to rely on script-end cleanup?
If later code, another component, or deferred work might still issue queries through the connection, do not close it prematurely. Close early only when the application can establish that the connection is no longer needed. Otherwise, for an ordinary connection, letting PHP clean it up at script end is supported behavior.
Rank #2
How persistent connections change the answer
A persistent connection is retained for reuse rather than closed when an individual script ends. Reuse may avoid the overhead of establishing a new connection, but persistent connections can remain open across requests and consume database connection capacity. The PHP Manual cautions that PDO does not automatically clean up persistent connections; state such as temporary tables, locks, and transactions may remain and affect later use.
Persistent connections therefore require deliberate attention to server connection limits, application worker counts, idle timeouts, and session state. Do not assume that ordinary end-of-script cleanup will close them, or that increasing the database’s maximum connection count is automatically the right fix. See the PHP Manual’s persistent connection guidance.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsQuick Recap
Rank #4
Practical decision guide
- Ordinary PDO or MySQLi connection, script is about to end: explicit close is generally unnecessary; PHP releases it at script end.
- Database work is finished, with substantial non-database processing left: close the ordinary connection early if you can be sure it will not be used again.
- More queries may still happen: keep the connection available until that work is complete.
- Persistent connection: plan for reuse, connection capacity, and cleanup of session state rather than expecting script end to close it.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




