yii mysql server has gone away on insert query

I am trying one cron job after running of 5 minutes it is giving me below error.

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]:

General error: 2006 MySQL server has gone away.

The SQL statement executed was: INSERT INTO phpcrawler_links

(site_id, depth, crawl_now, url, last_crawled,

http_status_code, content_type, page_size, parent_url_id)

VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7, :yp8)

Here by i am attaching screen shot for that.I am using yii framework.

Seems that you have problem with MySQL server, because it has gone away.

Have you tried to launch same sql direcly on mysql?

If your cronjob does the connection and then take a long time before executing the query is possible that mysql close the connection due to inactivity (connection timeout).

Just check if it is still alive and eventually reconnect.

you can do it with a try catch, something like

try {

	//execute the insert

} catch (Exception $e) {

	// the insert failed so reconnect and then execute the insert again 


Eventually in the catch you can check $e->getCode() to verify that the error code is the one of the connection and retry the connection, otherwise throw the exception