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:5
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Oct 19 15:01:26 2018 UTC