php file_get_contents超时

方法一

$ctx = stream_context_create(array(
  'http' => array('timeout' => 1))
);
file_get_contents("http://g.cn/", false, $ctx);

方法二

int_set('default_socket_timeout', 300);//设置超时300秒   
file_get_contents("http://g.cn/");  

若对方主机有反应,只是非常慢,则不会在上述超时时间退出程序

php/socket_timeout.txt · 最后更改: 2012/04/15 23:08 由 admin
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki