Consider the following scenario: We have an AWS worker instance (SQS based) which opens persistent MySQL connections to our RDS.
$this->connectRegistry[ $host ][ 'connect' ] = mysqli_connect(
"p:" . $host ,
$this->hostCredentials[ $host ][ 'username' ] ,
$this->hostCredentials[ $host ][ 'password' ]
);
Now sometimes - not on a regular basis - this call genertes the following warning:
PHP Warning: mysqli_connect(): MySQL server has gone away
As AWS worker instances are handling requests with a web-server, the setup basically identical to a usual instance which serves a website. We use the same class in multiple projects but in not a single website this error has even occurred once.
To get an idea where these warnings originates from we have tried to print a stack trace if a connection error occurs but - and now the awkward thing starts to come in - there is no connect error. Please take a look at the whole connect function:
private function connect ( $host )
{
$this->connectRegistry[ $host ][ 'connect' ] = mysqli_connect(
"p:" . $host ,
$this->hostCredentials[ $host ][ 'username' ] ,
$this->hostCredentials[ $host ][ 'password' ]
);
$error = mysqli_connect_error();
if( $error ) {
$this->raiseError( "Connect (" . mysqli_connect_errno() . ") " . $error );
return false;
}
return true;
}
The method raiseError
builds a complete error message with a stack trace and so on and then calls trigger_error
. However, this method is not called if the above-mentioned warning is triggered.
Our first goal is to know in which cronjobs these warnings are triggered - maybe there are some bad performing queries.