I've got a simple script running as a cron job that's getting intermittent "Lost connection to MySQL server during query" errors.

The script sends out listserve messages, 50 BCCs each minute, sleep()ing for 60 seconds between sends and updating a data table after each send. The whole BCC list varies from one message to the next, but messages typically take 10 or more sends in batches of 50 recipients.

Inconsistently, the script aborts with the lost connection error after a varying number of sends. Rarely it bombs not at all and performs all 10 or 12 updates without error.

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;

In an attempt to cure the problem I'm re-establishing the $conn before each query and doing a mysql_close() after each query, but the error still occurs.

The hosting is Media Temple's gridserver. I've never encountered this error in any of the many PHP/mysql scripts I run on Media Temple accounts, but this is different as it's a cron job.

Can you suggest aspects of the process that might lead to this error that I should look at more carefully? I can understand that sleep() might lose the connection between PHP & the MySQL server, but why would the script be unable to reconnect after sleeping? Would that be a server-dependent issue or is there something I can do in PHP to nail down the connectivity?

I'm hoping to get assistance on this issue without having to clean up the script enough to invite in guests, but I'll do so if required.

Thanks,

Paul


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

Reply via email to