mysqli_query(): MySQL server has gone away for Curl Request

I have created a WordPress Plugin which after activating shows result in jquery Datatable. We are fetching the result via CURL Post. The Post URL is a ASP.Net Application on Windows Server.

The plugin is created for my client who is experiencing below error after adding my shortcode in a Post.

Client is using Elegant Themes’ Divi (latest version), WordPress 5.2.2 running on Apache / PHP 7.2.21

This error is showing only on that Post page where the shortcode is added:

Warning: mysqli_query(): MySQL server has gone away in /homepages/10/d241347454/htdocs/wp-includes/wp-db.php on line 2007

Warning: mysqli_query(): Error reading result set’s header in /homepages/10/d241347454/htdocs/wp-includes/wp-db.php on line 2007

Here is my Plugin Code:

$atts = shortcode_atts(

‘secretkey’ => ”

$thisoptions = get_option( ‘MySecretKeySettings’ );

$url = ‘’;
$webApiUn = $thisoptions[‘webApiUn’];
$webApiPwd = $thisoptions[‘webApiPwd’];
$webApisecretkey = $atts[‘secretkey’];

$data = array(‘webApiUn’ => $webApiUn, ‘webApiPwd’ => $webApiPwd, ‘SecretKey’ => $webApisecretkey);
$data_string = json_encode($data);

$ch = curl_init($url);

//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
‘Content-Length: ‘ . strlen($data_string))
curl_setopt($ch, CURLOPT_TIMEOUT,75);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);

//execute post
$result = curl_exec($ch);

$endresult = json_decode($result);

foreach ($endresult->reviews->review as $key=>$value) {?>
<td><?php echo time_elapsed_string($endresult->reviews->review[$key]->datePublished); ?></td>
<td> <?php echo $endresult->reviews->review[$key]->rating; ?></td>

<td>More Data….</td>
<?php } ?>

I am not able to replicate the error which my client is reporting. On my end everything is working like a charm.

Please guide my on how can this be fixed.

Read more here:: mysqli_query(): MySQL server has gone away for Curl Request

Leave a Reply

Your email address will not be published. Required fields are marked *