Bug #70505 [NEW]: mysqli_poll does not honor timeout when multiple queries given
| From: | bishop@php.net | Date: | Tue, 15 Sep 2015 15:15:32 +0000 |
| Subject: | Bug #70505 [NEW]: mysqli_poll does not honor timeout when multiple queries given | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196016@lists.php.net to get a copy of this message | ||
From: bishop
Operating system: any? or 3.14.27-25.47.amzn1.x86_
PHP version: 5.6.13
Package: MySQLi related
Bug Type: Bug
Bug description:mysqli_poll does not honor timeout when multiple queries given
Description:
------------
When mysqli_poll is given a single link in its read array, and the async
query on that link runs longer than the timeout, the timeout expires and
poll returns (correctly) that nothing is ready to read.
However, in the same scenario when there are multiple links to read,
mysqli_poll ignores the timeout and returns only when the longest
running query resolves.
The man page is light on this function, so maybe I am misunderstanding
how timeout should work. Also, there's further discussion at this SO
post: http://stackoverflow.com/a/32576278/2908724
Test script:
---------------
$link0 = mysqli_connect(...);
$link1 = mysqli_connect(...);
$link2 = mysqli_connect(...);
$sql0 = 'SELECT SLEEP(2) AS wait, 1 AS num';
$sql1 = 'SELECT foo FROM';
$sql2 = 'SELECT 2 AS num';
mysqli_query($link0, $sql0, MYSQLI_ASYNC);
mysqli_query($link1, $sql1, MYSQLI_ASYNC);
mysqli_query($link2, $sql2, MYSQLI_ASYNC);
$links = array ($link0, $link1, $link2);
$begin = microtime(true);
$i = 0;
do {
printf("start i=%d @ T+%.f\n", $i, (microtime(true)-$begin));
$read = $error = $reject = $links;
$count = mysqli_poll($read, $error, $reject, 1, 500000);
if (0 < $count) {
foreach ($links as $j => $link) {
$result = mysqli_reap_async_query($link);
if (is_object($result)) {
printf("link #%d, row=%s\n", $j,
json_encode($result->fetch_assoc()));
mysqli_free_result($result);
} else if (false !== $result) {
printf("link #%d, output=%s\n", $j, $link);
} else {
printf("link #%d, error=%s\n", $j,
mysqli_error($link));
}
}
}
printf(
"finish i=%d, count(read, error, reject)=(%d, %d, %d) @
T+%f\n\n",
$i++, count($read), count($error), count($reject),
(microtime(true)-$begin)
);
} while (count($links) !== count($read) + count($error) +
count($reject));
Expected result:
----------------
start i=0 @ T+0.000000
link #0, row=null
link #1, error=You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '' at line 1
link #2, row={"num":"2"}
finish i=0, count(read, error, reject)=(1, 1, 0) @ T+1.500000
start i=1 @ T+1.500000
link #0, row={"wait":"0",a"num":"2"}
link #1, row=null
link #2, row=null
finish i=0, count(read, error, reject)=(1, 0, 2) @ T+2.000000
Actual result:
--------------
start i=0 @ T+0.000002
link #0, row={"wait":"0","num":"1"}
link #1, error=You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '' at line 1
link #2, row={"num":"2"}
finish i=0, count(read, error, reject)=(1, 0, 0) @ T+2.001756
start i=1 @ T+2.001827
finish i=1, count(read, error, reject)=(0, 0, 3) @ T+3.503024
--
Edit bug report at https://bugs.php.net/bug.php?id=70505&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70505&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70505&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70505&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70505&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70505&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70505&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70505&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70505&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70505&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70505&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70505&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70505&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70505&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70505&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70505&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70505&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70505&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70505&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70505&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70505&r=mysqlcfg