MysqlQuery force timeout from PHP

Is there a way to force Mysql from PHP to kill the request if it has not returned within a certain period of time?

Sometimes I see expensive requests that work for several hours (obviously, by this time the timeout for the HTTP connection or user has expired). As soon as the number of such requests accumulates, they begin to adversely affect the overall performance.

+3
source share
2 answers

Long requests are a sign of poor design. It is best to check the questions of interest and how they can be optimized. It just ignores the problem.

, SHOW PROCESSESLIST . KILL x, . PHP script, . , , PHP, .

+4

: - upstart.

DAEMONS , cron.
script, xyz time .

// this instruction kills all processes executing for more than 10 seconds
SELECT CONCAT('KILL ',id,';') 
FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE state = "executing" AND `time` >= 10

, ... , .

, , -. , , , .

+1

Source: https://habr.com/ru/post/1760841/


All Articles