如果在PHP页面上没有连续关闭MySQL连接,会发生什么情况? [英] What happens if MySQL connections continually aren't closed on PHP pages?

查看:101
本文介绍了如果在PHP页面上没有连续关闭MySQL连接,会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每个PHP页面的开头,我打开了与MySQL的连接,在整个页面中使用它,并在页面末尾将其关闭.但是,我经常在页面中间重定向到另一个页面,因此在这种情况下,连接不会关闭.我知道这对Web服务器的性能来说还不错,因为PHP还是会在每页末尾自动关闭所有MySQL连接.这里还有其他需要牢记的问题吗,还是真的不必担心要用PHP关闭数据库连接?

At the beginning of each PHP page I open up the connection to MySQL, use it throughout the page and close it at the end of the page. However, I often redirect in the middle of the page to another page and so in those cases the connection does not be closed. I understand that this is not bad for performance of the web server since PHP automatically closes all MySQL connections at the end of each page anyway. Are there any other issues here to keep in mind, or is it really true that you don't have to worry about closing your database connections in PHP?

$mysqli = new mysqli("localhost", "root", "", "test");
...do stuff, perhaps redirect to another page...
$mysqli->close();

推荐答案

来自: http://us3.php.net/manual/zh/mysqli.close.php

打开的连接(和类似资源)在脚本执行结束时会自动销毁.但是,您仍然应该在不再需要它们时立即关闭或释放所有连接,结果集和语句句柄.这将有助于返回资源更快地用于PHP和MySQL."

"Open connections (and similar resources) are automatically destroyed at the end of script execution. However, you should still close or free all connections, result sets and statement handles as soon as they are no longer required. This will help return resources to PHP and MySQL faster."

这篇关于如果在PHP页面上没有连续关闭MySQL连接,会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆