PHP MySQL设置连接超时 [英] PHP MySQL set Connection Timeout

查看:407
本文介绍了PHP MySQL设置连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于MySQL连接的某些帖子使用mysql.connect_timeout从PHP超时.我想知道是否从PHP设置的超时只是使与MySQL的初始连接超时还是对数据库的特定查询有效?

There are certain posts on MySQL connection set time out from PHP using mysql.connect_timeout. I want to know if this set timeout from PHP just time out the initial connection to MySQL or valid for a particular query to database?

我的情况是,我的页面顶部有一个与MySQL的连接,然后我一个又一个地执行对MySQL的3-4个查询.第一个和第二个查询只需要1-2秒即可执行,而第三个查询则需要20秒.现在,如果第三次查询花费的时间超过20秒,我想打电话超时.因此,这里的问题是,从PHP设置此超时适用于与数据库的初始连接,或者也适用于每个后续查询(独立地).如果是稍后的情况,那么我如何将其设置为20秒后进行第三次查询的超时?

My case here is that, I have a page with connection to MySQL on top and then I am executing say 3-4 queries to MySQL one after the another. 1st and 2nd query taken only 1-2 seconds to execute where as 3rd query takes 20 seconds. Now, in cases when 3rd query is taking more than 20 seconds, I want to call time out. So, the question here is that, setting this time out from PHP is applicable to initial connection to database or it is applicable to every subsequent query as well (independently). If later is the case, then how I can set it to timeout after 20 seconds for 3rd query?

推荐答案

connect_timeout参数仅在连接时有效.检查数据库服务器在20秒左右的时间内是否可以访问非常有用.连接后,指定的超时将不再有效.

The connect_timeout parameter is only valid at connection time. It's useful to check if your DB server is reachable in 20 seconds or so. Once connected the specified timeout is no longer valid.

我在官方的mysql手册页上找不到任何查询超时参数: http://dev.mysql.com/doc/refman/5.5/zh-CN/server-system-variables.html ,所以我认为这不可能.

I don't find any query timeout parameter on official mysql manual page: http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html so I don't think this is possibile.

这篇关于PHP MySQL设置连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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