file_get_contents函数的超时控制(default_socket_timeout)

<?php
$url = 'http://www.cnblogs.com/Zjmainstay/archive/2012/03/08/PHP_FUNCTION_file_get_contents.html';
$bad_url = 'http://www.cnblogs.com/Zjmainstay/archive/2012/03/08/PHP_FUNCTION_file_get_contents_bad.html';
ini_set('default_socket_timeout', 3);  /*超时控制(3秒)*/
if($data = file_get_contents($bad_url)) {
    echo $data;
}else {
    echo 'Timeout';
}
if($data = file_get_contents($url)) {
    echo $data;
}else {
    echo 'Timeout';
}
//End_php

原文地址:https://www.cnblogs.com/Zjmainstay/p/PHP_FUNCTION_file_get_contents.html