|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesmysql_pconnect-should-reconnect-in-all-error-cases.patch (last revision 2016-03-02 08:30 UTC by pch at ordbogen dot com)Pull Requests |
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 23:00:02 2025 UTC |
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