简体   繁体   English

PHP确实die()函数断开了mysql的连接?

[英]PHP does die() function disconnects mysql?

I'm always calling mysqli_close() before issuing die() command. 我总是在发出die()命令之前调用mysqli_close()

It's tedious and sometimes forgettable, but I want to make sure if the die command closes all mysql connections or does it still leave it opened? 这很乏味,有时候会被遗忘,但我想确定die命令是否关闭所有mysql连接还是仍然保持打开状态?

I can't check via PHP since the script stops after the die() command. 我无法通过PHP检查,因为脚本在die()命令后停止。

When script execution ends, all non persistent resources are closed. 当脚本执行结束时,将关闭所有非持久性资源。

In short, it is entirely safe to just bail out of execution. 简而言之,只是保释执行是完全安全的。 PHP will handle closing everything for you. PHP将为您处理关闭所有内容。 (Except, once again, for persistent connections, though those need somewhere to stay open, so if you're just the plain PHP executable without a webserver wrapped around it, those will be closed too.) (除了,再一次,对于持久连接,虽然那些需要保持打开的位置,所以如果你只是普通的PHP可执行文件没有包围它的web服务器,那么它们也将被关闭。)

Side note: I've never been able to find any official documentation of this, so you probably shouldn't depend on it, but from some testing I did a few weeks ago when a similar question was asked, it seems that resources are closed immediately upon going out of scope. 旁注:我从来没有找到任何这方面的官方文档,所以你可能不应该依赖它,但是几周前我做过的一些测试,当问到一个类似的问题时,似乎资源已关闭一旦超出范围,立即。 I also only tested with file and mysql connection resources, so it might just be those. 我也只测试了文件和mysql连接资源,所以它可能只是那些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM