php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76048 PDO Mysql max_execution_time is not respected
Submitted: 2018-03-05 07:37 UTC Modified: 2018-03-05 08:32 UTC
Votes:15
Avg. Score:4.7 ± 0.7
Reproduced:13 of 13 (100.0%)
Same Version:7 (53.8%)
Same OS:8 (61.5%)
From: rishabh dot pugalia at gmail dot com Assigned:
Status: Open Package: PDO MySQL
PHP Version: 7.0.28 OS: Mac
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rishabh dot pugalia at gmail dot com
New email:
PHP Version: OS:

 

 [2018-03-05 07:37 UTC] rishabh dot pugalia at gmail dot com
Description:
------------
PDO does not respect MySQL 5.7's new feature - max_execution_time()

The code below will explain further. Sadly the mysqli_* seg faults if the same native prepared statement is executed.

Test script:
---------------
<?php

$connection = new PDO("mysql:host=127.0.0.1;dbname=experiments", 'root', '');

// Setting this to true triggers a query directly but still the result is same (which is also weird)
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

// The query is supposed to take about 6s to execute
$stmt = $connection->prepare("select /*+ max_execution_time(1000) */ * from users where name = ?");

$stmt->execute(['b08588d6-0f12-11e8-9637-7e0088aab9a1']);

var_dump($stmt->fetchAll());

var_dump($connection->errorInfo());

Expected result:
----------------
It should throw an error around what Mysql natively does:

"ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded"

Actual result:
--------------
array(0) {
}
array(3) {
  [0]=>
  string(5) "00000"
  [1]=>
  NULL
  [2]=>
  NULL
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-05 08:18 UTC] saurav1991 at gmail dot com
When client side prepared statement is used i.e PDO::ATTR_EMULATE_PREPARES => true, the expected error PDOException: SQLSTATE[HY000]: General error: 3024 Query execution was interrupted, maximum statement execution time exceeded is thrown

However on using server side prepared statements, this exception is not thrown.

Compared with a ruby script using the mysql2 client. The exception is thrown both when server side prepared statement is used and when prepared query is sent to mysql directly.

This might have to do with how the prepared statement APIs of libmysqlclient are being used internally.
 [2018-03-05 08:32 UTC] rishabh dot pugalia at gmail dot com
-Summary: max_execution_time is not respected +Summary: PDO Mysql max_execution_time is not respected
 [2018-03-05 08:32 UTC] rishabh dot pugalia at gmail dot com
Adding "PDO Mysql" to the title.
 [2018-06-20 15:56 UTC] anthony at catsone dot com
I'm also running into this issue. 100% reproducible as per the original reporter.
 [2019-07-01 06:50 UTC] Fractalizer at yandex dot ru
Is reproducable on PHP 7.2 also. Any chances to have this fixed?
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Oct 14 15:01:26 2019 UTC