Been there (we all have) ... and in many respects, am still there (constantly learning) ... sooooo here's some more info to share with your local expert:
Fact that the process begins, gets to 500+ seconds then quits with 'server has gone away' could be due to mysql time outs (as already suggested), but that error could also occur IF the DB server gets a packet too large (max_allowed_packet). Quizs do have a lot of data that Moodle would attempt to send to the DB server in one big chunk.
http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
Something to try: set max_allowed_packet to a higher value ... say 16M and try it again.
If it fails again with same error, increase it again to 32M, restart mysqld, and try it again.
'spirit of thinkering', Ken