简体   繁体   English

MySQL服务器已消失在服务器上的错误

[英]MySQL server has gone away error on server

I have the following code about storing info about arXiv.org pages in mysql 我有以下关于在MySQL中存储有关arXiv.org页面信息的代码

function paper_info($paper_id){
    $url = 'http://arxiv.org/abs/'.$paper_id;
    $options = array('http'=>array('method'=>"GET", 'header'=>"User-Agent: Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko\r\n"));
    $context = stream_context_create($options);
    $sites_html = file_get_contents($url, false, $context);
    $html = new DOMDocument();
    @$html->loadHTML($sites_html);
    $title = null;
    foreach($html->getElementsByTagName('meta') as $meta) {
        if($meta->getAttribute("name")=="citation_title"){ 
            $title = $meta->getAttribute('content');
        }
    }
    if(preg_match('~<blockquote class="abstract mathjax">(.*?)</blockquote>~si', $sites_html, $match)){
        $abstract = trim(preg_replace('#<span class="descriptor">(.*?)</span>#', '', $match[1]));
    }   

    return array($title, $abstract);
}
            $paper_id = "1509.05363v1";
            if(!isset($paper_info)) $paper_info = paper_info($paper_id);        
            mysql_query("INSERT INTO `data` (`ID`, `Action`, `Value`) VALUES (NULL, 'Submit', '0');");  
            mysql_query("INSERT INTO `data` (`ID`, `Action`, `Value`) VALUES (NULL, 'Paper ID', '".$paper_id."');");
            mysql_query("INSERT INTO `data` (`ID`, `Action`, `Value`) VALUES (NULL, 'Title', '".mysql_real_escape_string($paper_info[0])."');");
            mysql_query("INSERT INTO `data` (`ID`, `Action`, `Value`) VALUES (NULL, 'Abstract', '".mysql_real_escape_string($paper_info[1])."');"); 

The code works fine on localhost however, when I uploaded my site on online server this error happens 该代码在本地主机上工作正常,但是,当我在在线服务器上上传网站时会发生此错误

MySQL server has gone away MySQL服务器不见了

I tried increasing the max_allowed_packet as it was suggested in MySQL error 2006: mysql server has gone away by adding the line 我尝试按照MySQL错误2006中的建议增加max_allowed_packet 通过添加以下行, mysql服务器已消失

mysql_query("SET GLOBAL max_allowed_packet = 1073741824;");

but the error still happens. 但是错误仍然会发生。 Does anyone know why this happens? 有谁知道为什么会这样吗?

After trying this 尝试这个之后

mysql_query("SET SESSION wait_timeout = 300;");
mysql_query("SET GLOBAL interactive_timeout=300;");
mysql_query("SET GLOBAL wait_timeout=300;");

the error doesn't happen now but the function paper_info return empty value on server but works fine on localhost. 该错误现在不会发生,但是函数paper_info在服务器上返回空值,但在localhost上可以正常工作。 Why is this happening? 为什么会这样呢?

Have you tried setting wait_timeout AND interactive_timeout value? 您是否尝试过设置wait_timeout AND interactive_timeout值?

Example: 例:

SET GLOBAL wait_timeout=300; 
SET GLOBAL interactive_timeout=300;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM