Bug #71699 [NEW]: mysql_pconnect ignores all errors but CR_SERVER_GONE_ERROR

From: Date: Wed, 02 Mar 2016 08:30:07 +0000
Subject: Bug #71699 [NEW]: mysql_pconnect ignores all errors but CR_SERVER_GONE_ERROR
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199558@lists.php.net to get a copy of this message
From:             pch at ordbogen dot com
Operating system: Linux
PHP version:      5.6.18
Package:          MySQL related
Bug Type:         Bug
Bug description:mysql_pconnect ignores all errors but CR_SERVER_GONE_ERROR

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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=71699&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71699&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71699&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71699&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71699&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71699&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71699&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71699&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71699&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71699&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71699&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71699&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71699&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71699&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71699&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71699&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71699&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71699&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71699&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71699&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71699&r=mysqlcfg



Thread (1 message)

  • pch at ordbogen dot com
« previous php.bugs (#199558) next »