php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71699 mysql_pconnect ignores all errors but CR_SERVER_GONE_ERROR
Submitted: 2016-03-02 08:29 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: pch at ordbogen dot com Assigned:
Status: Open Package: MySQL related
PHP Version: 5.6.18 OS: Linux
Private report: No CVE-ID: None
 [2016-03-02 08:29 UTC] pch at ordbogen dot com
Description:
------------
When mysql_pconnect attempts to reuse an existing connect, it calls mysql_ping to check the state of the connection, but it ignores all errors but CR_SERVER_GONE_ERROR.

If you use ext/mysql together with mysqlnd and trigger the PHP memory limit before all data have been fetched from the result set, the MySQL connection will not be in the ready state when it is being reused, causing mysql_ping to fail with a CR_COMMANDS_OUT_OF_SYNC.

Instead of treating CR_SERVER_GONE_ERROR, mysql_pconnect should probably just always create a new connection if mysql_ping fails, regardless of the error. This also seems to be how MySQLi and PDO handles it.

Test script:
---------------
<?php
header('Content-Type: text/plain');
error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', 'on');
ini_set('html_errors', 'off');

echo('PID: ' . getmypid() . "\n");

$link = mysql_pconnect($hostname, $username, $password);
if ($link === false)
  die('mysql_pconnect failed');
$res = mysql_query($some_query_with_lots_of_data, $link);
if ($res === false)
  die('mysql_query failed: ' . mysql_error($link);
for ($i = 0; $i != 1000; ++$i)
  mysql_fetch_assoc($res);

Expected result:
----------------
PID: xxxx

Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 43994880 bytes) in test.php on line 12

Actual result:
--------------
PID: 2604
mysql_query failed: Commands out of sync; you can't run this command now

Patches

mysql_pconnect-should-reconnect-in-all-error-cases.patch (last revision 2016-03-02 08:30 UTC by pch at ordbogen dot com)

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC