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

admin2025-01-08  3

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 = '';  
        $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.

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.

Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Sep 12, 2019 at 7:48 vanuragvanurag 1117 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736269915a1389.html

最新回复(0)