Home  >  Article  >  Backend Development  >  PHP如何控制Mysql执行时间

PHP如何控制Mysql执行时间

WBOY
WBOYOriginal
2016-06-06 20:31:591321browse

在php后台, 我们经常要做一些mysql长查询. 假如一条sql执行时间60秒, php可否设定如果msyql 执行时间超过30秒时, 需要终止mysql查询.

回复内容:

在php后台, 我们经常要做一些mysql长查询. 假如一条sql执行时间60秒, php可否设定如果msyql 执行时间超过30秒时, 需要终止mysql查询.

php.ini有个设置可以来设定一个请求里的mysql连接超时时间。

<code>php</code><code>ini_set('mysql.connect_timeout', 30); 
</code>

但是这是针对你脚本里所有本次的请求mysql的超时时间,你的问题是想设置一条sql的超时时间,这个是没有的,貌似办不到。

mysqli的话,还能设置
$mysqli = mysqli_init();
$mysqli->options(MYSQL_OPT_READ_TIMEOUT, 30);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn