I'm trying to send 750 emails through cron job.
After it sends nearly 40 emails, like after a few minutes it throws this error,

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away' in /public_html/ehs/includes/database/database.inc:2171 Stack trace: #0 /public_html/ehs/includes/database/database.inc(2171): PDOStatement->execute(Array) #1 /public_html/ehs/includes/database/database.inc(683): DatabaseStatementBase->execute(Array, Array) #2 /public_html/ehs/includes/database/database.inc(2350): DatabaseConnection->query('select name, d...', Array, Array) #3 /public_html/ehs/sites/all/modules/elysia_cron/elysia_cron.module(424): db_query('select name, d...', Array) #4 /public_html/ehs/sites/all/modules/elysia_cron/elysia_cron.module(632): elysia_cron_get('rules_cron', false, 'running', 0, false) #5 /public_html/ehs/sites/all/modules/elysia_cron/elysia_cron.admin.inc(753): elysia_cron_is_job_running('rules_cron') #6 [internal function]: elysia_cron_execute_page_cleanup() #7 {main} in /public_html/ehs/includes/database/database.inc on line 2171

I have tried upgrading max_allowed_packet to 500M under [mysqld] in my.ini and also php_memory_limit to 1024M, but still it didn't improve anything.
Is there any other possible thing I could do to resolve it?

FYI, I'm sending a view in emails to all the users using Insert view. The views are generated per user basis, and that involves aggregation operations and computed fields.


A few minutes to send 40 emails indicates that this cron job is computationally expensive. You are probably hitting against MySQL's wait_timeout limit.

I wouldn't necessarily suggest changing your MySQL configuration. Drupal's cron runs aren't meant to take more than a few minutes at a time. Instead, this may be better suited to a cron queue.

In a cron queue, each individual email to send would be a job in this particular queue. During each cron run, as many of those jobs in each queue are processed until some set time limit has passed, and the remaining jobs are deferred for the next cron run.

Not the answer you're looking for? Browse other questions tagged or ask your own question.