Avoid mysql timeout in new archive.php

On shared hostings (and maybe on very high traffic sites), if mysql timeout is set too short the scripts hits the error:


[2011-10-25 17:00:27] [6df61fe0] [8.85 Mb] START
[2011-10-25 17:00:27] [6df61fe0] [8.85 Mb] Starting Piwik reports archiving...
[2011-10-25 17:00:33] [6df61fe0] [8.86 Mb] Archived website id = 1, period = day, Time elapsed: 6.339s
[2011-10-25 17:00:41] [6df61fe0] [8.87 Mb] Archived website id = 1, period = week, 810 visits, Time elapsed: 8.156s
[2011-10-25 17:00:57] [6df61fe0] [8.87 Mb] Archived website id = 1, period = month, 4329 visits, Time elapsed: 15.839s
[2011-10-25 17:01:12] [6df61fe0] [8.87 Mb] Archived website id = 1, period = year, 19676 visits, Time elapsed: 14.653s
[2011-10-25 17:01:12] [6df61fe0] [8.92 Mb] ERROR: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
<br />
<b>Fatal error</b>:  SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in <b>/home/public_html/piwik/misc/cron/archive.php</b> on line <b>179</b><br />

Maybe the solution posted at PHP: MySQL Functions - Manual can be useful to avoid the timeout in the new archive.php.