From: xzzll at msn dot cn
Operating system: Centos7
PHP version: 7.3.12
Package: PDO Core
Bug Type: Bug
Bug description:Pdo close error
Description:
------------
Errors in some cases when pdo ends the connection.
I can't locate the details of this issue for now because it happens
randomly.
The demo code I provided is almost the same as the actual business code,
they work persistently under cli and perform close and reopen on timeout
connections.
However, the connection may be interrupted automatically due to network
fluctuations or server timeouts.When the mysql connection in some
processes is persistent and no activity is triggered again, an exception
occurs.(My mysql server is remote)
Msg : \Game\Sql\Pdo::close(): send of 5 bytes failed with errno=32
Broken pipe
Since the demo code is more than 20 lines, I scaled it. Please format it
and view it. I am very sorry for the trouble.
It is important to note that this problem does not absolutely recur, it
happens randomly, and when the problem occurs, it is in a long-term
vacant state.
Test script:
---------------
<?php
namespace test;class Pdo{public static $db;public static $start;public
static $timeout;
public static function init($config){try {
self::$db = new \PDO('mysql:dbname=' . $config['table'] .
';host=' . $config['server'] . ';port=' . $config['port'] .
';charset=utf8', $config['user'], $config['password'], [
\PDO::ATTR_PERSISTENT => false,
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
]);
} catch (\Throwable $th) {var_dump($th);return;}
self::$start = time();self::$timeout = (self::$db->query('show
variables like "wait_timeout"')->fetch(MYSQLI_ASSOC))['Value'];
echo ("-------------------MYSQLConnect timeout=" .
self::$timeout . " ServerVersion=" . self::$db->query('select
version()')->fetchColumn() . "-------------------");}
public static function close(){self::$db = null;}
public static function uinit(){self::close();$time =
microtime(true);echo ("-------------------ReConnect:" . $time .
"-------------------");self::init(require(__DIR__ .
'/think/config/MysqlConfig.php'));echo ("-------------------ConnectOk:"
. (microtime(true) - $time) . "-------------------");}
public static function test(){if (time() - self::$start >=
self::$timeout) {$this->uinit();}}
}
\test\Pdo::init(require_once __DIR__ .
'/think/config/MysqlConfig.php');
sleep(\test\Pdo::$timeout + 10); //The time here should actually be very
long
\test\Pdo::test(); //error
/*SyStemNotice:Code: 8
File: /root/Game/think/system/Sql/Pdo.php:29
Msg : \Game\Sql\Pdo::close(): send of 5 bytes failed with errno=32
Broken pipe*/
Expected result:
----------------
Ideally, it should close the connection normally, or end directly when
the connection is unavailable, so that the code can continue to perform
the connection work, but in fact it throws a notice error
Actual result:
--------------
/*
SyStemNotice:
Code: 8
File: /root/Game/think/system/Sql/Pdo.php:29
Msg : \Game\Sql\Pdo::close(): send of 5 bytes failed with errno=32
Broken pipe
*/
--
Edit bug report at https://bugs.php.net/bug.php?id=78972&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78972&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78972&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78972&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78972&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78972&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78972&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78972&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78972&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78972&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78972&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78972&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78972&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78972&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78972&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78972&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78972&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78972&r=mysqlcfg