curl有curlopt_connecttimeout可设,fsockopen有$timeout可设,而file_get_contents和fopen在打开url时,都不可设置响应时间timeout。如果url长时间没有响应,file_get_contents 会跳过短时间内没有响应的,而fopen会一直停留着等待,那么您的服务器就很可能挂了。


<?php
$url='"http://www.zzsky.cn';
$ctx=stream_context_create(array(
'http'=>array(
        'timeout'=>10//等待10秒
        )
    )
);
return file_get_contents($url,0,$ctx);
?>