Re: [PHP] losing mysql connection during cron job

2008-06-19 Thread Paul Novitski

At 6/18/2008 02:47 PM, Paul Novitski wrote:
I've got a simple script running as a cron job that's getting 
intermittent Lost connection to MySQL server during query errors.



At 6/18/2008 10:43 PM, Chris wrote:

You need to do a
mysql_close();
mysql_connect(...)

before mysql_query works again - otherwise mysql_connect will just
return the same resource id (or I guess just use the 'new_connection'
flag for mysql_connect and skip the mysql_close()).



Thanks!  Adding the new_link parameter to mysql_connect() did the trick.

What had me stumped before was that each mysql_connect() succeeded 
but the mysql_select_db() immediately afterward failed.  But as the 
documentation says:


new_link
If a second call is made to mysql_connect()  with the same 
arguments, no new link will be established, but instead, the link 
identifier of the already opened link will be returned. The 
new_link  parameter modifies this behavior and makes mysql_connect() 
always open a new link, even if mysql_connect() was called before 
with the same parameters.

http://ca3.php.net/mysql_connect

Reminder to self: RTFM doesn't always work if you think you know the 
page and don't re-read it with new eyes.


Cheers,
Paul 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] losing mysql connection during cron job

2008-06-18 Thread Shiplu

 The script cycle is, symbolically:

foreach (recipients as batch)
{
mail() using batch of recipients;
mysql_query() update table;
sleep(60);
}
final mysql_query() update table as complete;


why don't you edit your code?

   foreach (recipients as batch)
   {
   mail() using batch of recipients;
   mysql_query() update table;
   if(mysql_errno()==ERROR_CODE_YOU_GET){
 mysql_connect();
 mysql_select_db();
   }
   sleep(60);
   }


Re: [PHP] losing mysql connection during cron job

2008-06-18 Thread Paul Novitski

At 6/18/2008 04:49 PM, Shiplu wrote:

why don't you edit your code?

   foreach (recipients as batch)
   {
   mail() using batch of recipients;
   mysql_query() update table;
   if(mysql_errno()==ERROR_CODE_YOU_GET){
 mysql_connect();
 mysql_select_db();
   }
   sleep(60);
   }



Thanks for the suggestion.  I am currently successfully working 
around this error by another method, although your suggestion is 
probably better.


The reason I posted this problem, though, is that I want to 
understand *why* I'm getting the Lost connection to MySQL server 
during query error.


If anyone has had a similar experience using cron jobs or sleep() I'd 
love to hear from you.


Thanks,
Paul 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] losing mysql connection during cron job

2008-06-18 Thread Chris

 Thanks for the suggestion.  I am currently successfully working around
 this error by another method, although your suggestion is probably better.
 
 The reason I posted this problem, though, is that I want to understand
 *why* I'm getting the Lost connection to MySQL server during query error.
 
 If anyone has had a similar experience using cron jobs or sleep() I'd
 love to hear from you.

- database is restarted for whatever reason (log rotation, dba does an
upgrade etc etc).
- mysql has a 'wait_timeout' setting which could trigger it

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_wait_timeout

You need to do a
mysql_close();
mysql_connect(...)

before mysql_query works again - otherwise mysql_connect will just
return the same resource id (or I guess just use the 'new_connection'
flag for mysql_connect and skip the mysql_close()).

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php