note 93476 added to function.mysql-connect

From: Date: Fri, 11 Sep 2009 15:51:23 +0000
Subject: note 93476 added to function.mysql-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-160465@lists.php.net to get a copy of this message
If you are getting MySQL Errors like #2006: MySQL server has gone away, and you are using mysql_connect() and pcntl_fork() then make shure that you are reconnecting to the mysql server with each created child which you fork()ed. I pulled my hair out for many days because i was using the same mysql connection for each child and was getting that "MySQL server has gone away" errors. Here is a simple example: <?php $link = mysql_connect($db_server, $db_user, $db_pass); mysql_select_db($db_database,$link)); $pid = pcntl_fork(); if ($pid == -1) // Error forking child elseif ($pid) { // Parent will be here } else { // The child has to esablish a *new* mysql connection. // if you use mysql_connect without the 4th parameter // then it will use the connection from the parent. But // if the child dies, the connection will be unaviable in // the parent too. // So, note the "true" as 4th parameter. $newlink = mysql_connect($db_server, $db_user, $db_pass,true); mysql_select_db($db_database,$newlink)); // ... } ?> ---- Server IP: 217.160.72.57 Probable Submitter: 84.184.107.60 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php Edit -- https://master.php.net/note/edit/93476 Del: integrated -- https://master.php.net/note/delete/93476/integrated Del: useless -- https://master.php.net/note/delete/93476/useless Del: bad code -- https://master.php.net/note/delete/93476/bad+code Del: spam -- https://master.php.net/note/delete/93476/spam Del: non-english -- https://master.php.net/note/delete/93476/non-english Del: in docs -- https://master.php.net/note/delete/93476/in+docs Del: other reasons-- https://master.php.net/note/delete/93476 Reject -- https://master.php.net/note/reject/93476 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160465) next »