|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37319 "MySQL server has gone away", with PDO::ATTR_PERSISTENT => true
Submitted: 2006-05-05 02:40 UTC Modified: 2006-12-12 01:00 UTC
Avg. Score:4.3 ± 0.8
Reproduced:14 of 14 (100.0%)
Same Version:2 (14.3%)
Same OS:1 (7.1%)
From: j8859 at clix dot pt Assigned: wez (profile)
Status: No Feedback Package: PDO related
PHP Version: 5.1.3 OS: Linux Slackware 10.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: j8859 at clix dot pt
New email:
PHP Version: OS:


 [2006-05-05 02:40 UTC] j8859 at clix dot pt
This error also occurs with PHP 5.1.2, but with more frequency than with 5.1.3.

It occurs only if I use PDO::ATTR_PERSISTENT => true, and it never occurs with PDO::ATTR_PERSISTENT => false.

I have several databases in MySQL, several programs in PHP some using the classic MySQL functions, others using MySQLi, and one using PDO. This is the one which produces errors.

The MySQL version is 5.0.18. Apache/1.3.34.

If I do a MySQL Flush Tables, the error stops.
With PHP 5.1.2 I also need to do an Apache restart to get the error stop occurring.

The error never occurred with few MySQL tables opened.
I do a diary crontab backup with mysqldump, over the night, and in the morning there are about 220 opened tables.
Then, when I use my PDO application, I start getting "MySQL server has gone away" errors.

I changed to PDO::ATTR_PERSISTENT => false and the error never happened.
I changed back to PDO::ATTR_PERSISTENT => true and the error returned.

I know this can be difficult for you to reproduce it, because it is not a deterministic error, but I'm sure there is an error.

Reproduce code:
$bd = new PDO();
$query = "SELECT * FROM mytable";
$inst = $this->prepare($query);
if(!$inst) die ("ERROR: " . $query . ", " . __FILE__ . ", " .  __LINE__);
if(!$inst->execute()) { $inst->closeCursor(); return; }
while($reg = $inst->fetch(PDO::FETCH_ASSOC)) {
	// Process $reg
$bd = null;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-06 09:52 UTC] j8859 at clix dot pt
It occurs also with PHP 5.1.4.
 [2006-05-26 13:41 UTC] j8859 at clix dot pt
Apparently the problem stopped occurring.
I'll see what happens in the next days.
Anyway, the solution you suggest 
-- $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); --
is it a temporary or a definitive one?
 [2006-05-28 10:59 UTC] j8859 at clix dot pt
After applying your suggestion, the problem didn't occur again.
Anyway, I guess this should only be a temporary solution, isn't it?
 [2006-12-04 15:12 UTC]
Please try using this CVS snapshot:
For Windows:

 [2006-12-12 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-09-03 20:12 UTC] arsukdeo at technocorp dot com
Sep 03, 2008:

This problem might not be specific to a given version of linux, but with respect to the nature of the web server handles processes with PDO.
I have a client running:  php 5.1.6 on centos (Linux -.-.- 2.6.18-92.1.6.el5 i686)with apache 2.0 and the "MySQL server has gone away" problem still occurs.

Interestingly, I developed a core framework with the necessary db "access code" using PDO on XP with IIS and I did not see a problem until I tried to run the code on centos.  The access code uses ATTR_PERSISTENT set to true.

At the moment, I haven't found the triggering mechanism.  The client's server was standalone and there was no load on it.

In any case, this is a real problem that requires investigation and it should be fixed ASAP.
 [2009-01-22 14:46 UTC] bsr at gmail dot com
Can also add that I have the problem on Centos 5.2. For me, the problem exists whether persistent is set to true or false.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Nov 30 13:03:49 2021 UTC