什么时候应该使用mysqli_kill()和mysqli_close()? [英] When should I use mysqli_kill() and mysqli_close()?

查看:678
本文介绍了什么时候应该使用mysqli_kill()和mysqli_close()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我自己的数据库,我运行使用Xampp。我使用的Apache和MySql服务,虽然我给了公共访问只是还没有。我想知道正确的方法来结束一堆sql查询。我使用ajax发送数据到php页面,并从服务器查询一些数据。在ajax请求期间,我编程的处理程序php页面,所以它将执行多个查询(至少多于一个),以获得我需要的特定数据。现在,我不知道什么时候应该使用 mysqli_kill() mysqli_close()。我现在设置,所以只有在所有的特定的ajax请求的所有立即查询已执行,然后运行mysqli_close()。我甚至不使用mysqli_kill()。我不太了解数据库连接或管理服务器上的性能,因此我不知道如何来考虑这一点。一方面,我不需要关闭连接,直到用户注销网页,对吧?

I have my own database which I'm running using Xampp. I'm using the Apache and MySql services on it, though I given public access just yet. I would like to know the proper way to end a bunch of sql queries. I'm using ajax to send data to a php page and query some data from a server. During the ajax requests the I programmed the handler php page so it will be performing multiple queries (at least more than one) to get the specific data I need. Now, I don't know when in the process I should use mysqli_kill() or mysqli_close(). I have it set up right now so only after all the immediate queries for that particular ajax request have been performed, then run mysqli_close(). I don't even use mysqli_kill(). I don't know too much about database connections or managing performance on a server so I don't know how to consider this. On one hand, I don't need to close the connection until that user logs off the webpage, right? Or should I just open and close each connection as it comes and is processed?

此处理程序php页面处理来自我拥有的几个网页的请求,并在其中一个网页中处理请求是一个输入框,发送ajax请求每个击键以显示提示(可能的匹配)...还要注意,这是一个员工访问页面,所以连接不应该太高。

This handler php page processes requests from a few webpages I have and in one of the webpages there is an input box that sends ajax requests every keystroke to show hints (possible matches)... also note this is an employee access only page so connections shouldn't be too high.

我也看了一下这篇文章

I also took a look at this post Could someone explain a little about this statement about mysqli close function?

答案是:与从php手册网站采取的建议矛盾。有人请澄清什么时候使用 mysqli_kill() mysqli_close()以及如果,为了性能,有任何理由保持连接活动?

The answer is contradictory to the suggestion taken from the php manual website. Would someone please clarify when to use mysqli_kill() and mysqli_close() as well if, for the circumstances I described, there would be any reason to keep a connection alive for the sake of performance?

推荐答案

一般来说,你不需要使用任何一个这些功能。当PHP脚本完成执行时,服务器分配给您的所有资源都会自动释放,因此在最常见的情况下,您不应该关心它。

In general, you do not need to use either of these functions at all. All resources that the server has allocated to you will be released automatically when the PHP script finishes executing, so in the most common scenario there is nothing you should be concerned about.

有时你可能想使用 mysqli_close ,例如在一个长时间运行的脚本中,它已经做了它需要做的数据库,并且不希望绑定服务器资源

Sometimes you might want to use mysqli_close, for example inside a long-running script that has done what it needs to do with the database and does not wish to tie up server resources for the remainder of its execution.

你应该永远不需要使用 mysqli_kill :这个函数是什么指示服务器销毁工作线程。这是进入捣蛋在你不被邀请的地方,这在某些情况下可能是有用的,但肯定从来没有正常操作。

You should never have need to use mysqli_kill at all: what this function does is instruct the server to destroy a worker thread. This is getting into "mucking around where you are not invited" territory, which might be useful in some situations but certainly never under normal operation.

这篇关于什么时候应该使用mysqli_kill()和mysqli_close()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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