doukong1901 2014-01-14 18:01
浏览 301

mysqli_connect()突然非常慢

I have not changed anything in this situation recently, but recently my mysqli_connect() to a remote server is very slow (about half the time it hits the 30 second max execution time). When it works, the response time is between 28 and 30 seconds.

I have restarted MySQL on both servers. The server holding the PHP script is a local WAMP server, the remote server is a LAMP stack. The LAMP server performs fine serving the same information that the WAMP server is requesting. The queries do not appear to be the issue, instead it looks like mysqli_connect() is the problem:

    $mtime = microtime(); 
    $mtime = explode(" ",$mtime); 
    $starttime = $mtime[1] + $mtime[0]; 
        $this->conn = mysqli_connect($this->host,$this->user,$this->password) or die(mysqli_error($this->conn));
        $etime = microtime(); 
    $etime = explode(" ",$etime); 
    $endtime = $etime[1] + $etime[0]; 
    $totaltime = ($endtime - $starttime);  
    echo('<!--mysqli_connect took: '.$totaltime.' seconds-->');

The page (when it does not give a 500 response for hitting max_execution_time) will show:

<!--mysqli_connect took: 28.975151777267 seconds-->

The same code on the remote LAMP server will show:

<!--mysqli_connect took: 0.036190032958984 seconds-->

I have not updated this code or made any configuration changes since this was working. I get no errors on either server except for the max_execution_time exceeded error when it goes past 30 seconds on the WAMP server. Does anyone have any suggestions?

Thanks for reading.

  • 写回答

2条回答 默认 最新

  • dpvr49226 2014-01-14 18:09
    关注

    Perhaps a DNS issue? Have you tried changing your host string to a straight IP address rather than say a domain? There was a similar question here, Connecting to mysql server(localhost) very slow , that sounded similar however it was local host and changing to 127.0.0.1 fixed the issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试