我有以下代码关于在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])."');");
代码在localhost上工作正常但是,当我在在线服务器上传我的网站时,会发生此错误
MySQL服务器已经消失
我尝试按照MySQL error 2006: mysql server has gone away中的建议增加max_allowed_packet
来添加行
mysql_query("SET GLOBAL max_allowed_packet = 1073741824;");
但错误仍然存在。有谁知道为什么会这样?
尝试此后
mysql_query("SET SESSION wait_timeout = 300;");
mysql_query("SET GLOBAL interactive_timeout=300;");
mysql_query("SET GLOBAL wait_timeout=300;");
错误现在没有发生,但函数paper_info
在服务器上返回空值但在localhost上正常工作。为什么会这样?
答案 0 :(得分:0)
您是否尝试过设置wait_timeout AND interactive_timeout
值?
示例:
SET GLOBAL wait_timeout=300;
SET GLOBAL interactive_timeout=300;