The error you are receiving directly
MySQL server has gone away
is definitely caused by the MySql server being down. If the MySql Server and the PHP script are on the same VPS, then you are going to need to hunt down exactly what is causing the database to shut down (crash). Check the server error logs. They should tell you what the problem is.
Instead of performing the query the way you have written, why don't you simply do the following query instead:
$query = "SELECT count(*) FROM `emails` WHERE `email` = '".$email."'";
That way you can just pull the number of rows rather than all the data which runs quite a bit faster on MySql (especially if email
is indexed).
$query = "SELECT count(*) FROM `emails` WHERE `email` = '".$email."'";
$resultnx = mysql_query($query) or die(mysql_error());
$num_rows_array = mysql_fetch_array($resultnx);
$num_rows = $num_rows_array[0];
Lines in the code can be combined. They were separated to make it easier to see what was occurring.