intermittent MySQL server has gone away error intermittent MySQL server has gone away error curl curl

intermittent MySQL server has gone away error


This is probably happening because your CURL request is taking longer then the mysql connection timeout

either 1) set a request-timeout for CURL so it dies sooner on errors (CURLOPT_CONNECTTIMEOUT is only for connections- CURLOPT_TIMEOUT is for the overall length of the request and it will stop if the server doesn't respond in time)2) turn up the mysql idle timeouts to prevent the server from disconnecting you for not sending queries
3) detect the error and automatically reconnect to mysql

mysql> show variables like "%timeout%";+--------------------------+-------+| Variable_name            | Value |+--------------------------+-------+| connect_timeout          | 5     || delayed_insert_timeout   | 300   || innodb_lock_wait_timeout | 50    || interactive_timeout      | 28800 || net_read_timeout         | 30    || net_write_timeout        | 60    || slave_net_timeout        | 3600  || table_lock_wait_timeout  | 50    || wait_timeout             | 28800 |+--------------------------+-------+9 rows in set (0.00 sec)

wait_timeout and interactive_timeout are the two you care about