2

I have the following code about storing info about arXiv.org pages in mysql

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

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_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. Why is this happening?

Community
  • 1
  • 1
user3741635
  • 852
  • 6
  • 16
  • Check out http://stackoverflow.com/questions/12425287/mysql-server-has-gone-away-when-importing-large-sql-file –  Sep 21 '15 at 14:33
  • See [this so question](http://stackoverflow.com/questions/8062496/how-to-change-max-allowed-packet-size) and the [mysql documentation](https://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html) (for your version of mysql). That variable cannot be altered using SQL, it must be set up before the connection is established (my.cnf etc..) – Kenney Sep 21 '15 at 14:38

1 Answers1

0

Have you tried setting wait_timeout AND interactive_timeout value?

Example:

SET GLOBAL wait_timeout=300; 
SET GLOBAL interactive_timeout=300;
Arun Krish
  • 2,153
  • 1
  • 10
  • 15