note 99380 added to function.mysql-pconnect
| From: | seawyvern at gmail dot com | Date: | Fri, 13 Aug 2010 19:10:56 +0000 |
| Subject: | note 99380 added to function.mysql-pconnect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171659@lists.php.net to get a copy of this message | ||
(using PHP v5.3.2)
This might help other people who are running into a similar issue. I would occasionally get this
error in my apache error log:
PHP Warning: mysql_pconnect(): MySQL server has gone away
It appears the persistent connection mysql_pconnect() was returning had timed out and
mysql_pconnect() didn't detect it. To address this issue I added some code to check for this
case using mysql_ping() and request another connection from mysql_pconnect() if this situation
occurred. It appears that the combination of the checking for the time out with mysql_ping( ) and
re-requesting the connection with mysql_pconnect( ) either caused the original connection to
re-connect or forced mysql_pconnect() to recognize that the connection had timed out and request a
new one. The documentation for mysql_ping( ) says that it will force a re-connect if it detects a
timeout, however comments on the documentation page mention that this feature has been disabled for
some time. Anyways here is the code I used, hope it helps:
$dbConnection = mysql_pconnect( $myHostname, $myUsername, $myPassword );
if ( !mysql_ping( $dbConnection ) )
{
$dbConnection = mysql_pconnect( $myHostname, $myUsername, $myPassword );
}
----
Server IP: 69.147.83.197
Probable Submitter: 209.104.7.62
----
Manual Page -- http://www.php.net/manual/en/function.mysql-pconnect.php
Edit -- https://master.php.net/note/edit/99380
Del: integrated -- https://master.php.net/note/delete/99380/integrated
Del: useless -- https://master.php.net/note/delete/99380/useless
Del: bad code -- https://master.php.net/note/delete/99380/bad+code
Del: spam -- https://master.php.net/note/delete/99380/spam
Del: non-english -- https://master.php.net/note/delete/99380/non-english
Del: in docs -- https://master.php.net/note/delete/99380/in+docs
Del: other reasons-- https://master.php.net/note/delete/99380
Reject -- https://master.php.net/note/reject/99380
Search -- https://master.php.net/manage/user-notes.php