MySQLI_QUERY():MySQL服务器已离开以进行Curl请求

时间:2019-09-12 作者:vanurag

我创建了一个WordPress插件,激活后在jquery Datatable中显示结果。我们正在通过CURL Post获取结果。帖子URL是ASP。Net应用程序。

该插件是为在帖子中添加我的短代码后遇到以下错误的客户创建的。

客户端使用的是优雅主题的Divi(最新版本),WordPress 5.2.2运行在Apache/PHP 7.2.21上

此错误仅显示在添加了快捷码的帖子页面上:

警告:mysqli\\u query():MySQL服务器已消失在/homepages/10/d241347454/htdocs/wp includes/wp db中。php在线2007**

警告:mysqli\\u query():在/homepages/10/d241347454/htdocs/wp includes/wp db中读取结果集标题时出错。php在线2007**

以下是我的插件代码:

 $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 } ?>
我无法复制客户报告的错误。在我这边,一切都很顺利。

请指导我如何解决此问题。

1 个回复
SO网友:Bilal Ahmed

请看这张票。https://wordpress.org/support/topic/warning-mysqli_query-mysql-server-has-gone-away/#topic-9911138-replies

它与mysql内存耗尽有关,因为数据库大小较大或可能是数据包大小较低的内存。

相关推荐

使用cURL将文件下载到wp-Includes/Uploads

我有一个保存帖子的钩子,看起来像这样,它应该根据提供的视频id将youtube缩略图下载到wp包含/上传。但这并不能挽救任何东西。 add_filter( \'save_post\', function () { $video_id = \'VSB4wGIdDwo\'; $path_to_save_thumbnails = \'/wp-includes/upload/\'; $ch = curl_init();