0

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(
            array(

                'secretkey' => ''
            ),
            $atts,
            'MySecretKeyCaption'
        );

        $thisoptions = get_option( 'MySecretKeySettings' );

         $url = 'https://sub.someASPnetWebsite.com/api/TestimonialList';  
        $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) {?>
<tr>
<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>
</tr>
<?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.

0

Kindly refer to this ticket. https://wordpress.org/support/topic/warning-mysqli_query-mysql-server-has-gone-away/#topic-9911138-replies

Its related to mysql memory exhausted, due to large db size or might be low packet size memory.

| improve this answer | |
  • So this is something fixed from clients end? – vanurag Sep 12 '19 at 8:10
  • Yes its hosting related issue, ask your client to contact to his hosting provider to resolve this issue. – Bilal Ahmed Sep 12 '19 at 8:10
  • I saw the link you given before posting my question but still I am not very much sure if this is something fixed by clients end. I need to be very much sure and confident before sending him. – vanurag Sep 12 '19 at 8:15
  • Visit this official Mysql documentation. dev.mysql.com/doc/refman/8.0/en/…. Its narrated that By default, the server closes the connection after eight hours if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld – Bilal Ahmed Sep 12 '19 at 8:16
  • But I am not using any MySql query to show or fetch data in Jquery DataTable then why getting the Warning? – vanurag Sep 12 '19 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.