A: 

Quote from http://dev.mysql.com/doc/refman/5.0/en/gone-away.html:

The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection.
[...]
Some other common reasons for the MySQL server has gone away error are:
* You (or the db administrator) has killed the running thread with a KILL statement or a mysqladmin kill command.
* You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.
* A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.
* You got a timeout from the TCP/IP connection on the client side. This may happen if you have been using the commands: mysql_options(..., MYSQL_OPT_READ_TIMEOUT,...) or mysql_options(..., MYSQL_OPT_WRITE_TIMEOUT,...). In this case increasing the timeout may help solve the problem.
* You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).
* You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.

etc.

Frxstrem
I already read the mysql documentation. The problem is that the connection died if the image processing time is more than my mysql connection timeout. I know it. But why it doesn't work to connect me again to the mysql server. I found anything which could be the problem. I need help guys.
Darm Ret
A: 

first try increasing the timeout, then close the connection after step 4

mysql_close()

why increase the timeout? because the image processing definitely takes more than 5 secs, so this problem occurs!

sikas
increasing the timeout is not a good strategy, let's say I have a limit of 256 clients for the mysql server. If 256 users upload photo and it takes 40s. the mysql server could not handle other connection during 40s. What I want is just reconnect me to the mysql server after the image processing. This is what I write in the php code but it doesn't work.
Darm Ret