1

I am exploring the possibility of setting a timeout/stopping a specific query in PHP and MySQLi.

Slightly modified example from php.net:

if ($stmt = $mysqli->prepare("INSERT NESTED MYSQL QUERY HERE.")) {
    $stmt->bind_param("s", $city);
    $stmt->execute();
    $stmt->set_timeout("50000"); //hypothetical, will not work
    $stmt->bind_result($district);
    while($stmt->fetch()){ 
        //to do
    }
}
$mysqli->close();

Is this possible?

Ideal implementation:

  1. Inside PHP code and not through configuration of MySQL server
  2. Can be implemented only for selected queries and not to all queries
  3. Works (at a minimum) on MySQL 5.6 and beyond
  4. Can inform the end user, e.g.

The process took long than expected. Try to split your dataset into segments.

RockMyAlgorithm
  • 516
  • 1
  • 4
  • 14
  • Possible duplicate of: http://stackoverflow.com/questions/415905/how-to-set-a-maximum-execution-time-for-a-mysql-query – Rasclatt Nov 24 '15 at 06:55

1 Answers1

-1

Refer this

http://mysqlserverteam.com/server-side-select-statement-timeouts/

For read-only SELECT statement

SELECT 
MAX_STATEMENT_TIME = 2000 --in milliseconds
* 
FROM table;
Ninju
  • 2,522
  • 2
  • 15
  • 21