Tips:点此可运行HTML源码

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

posted @ 2012-03-08 22:31  Zjmainstay  阅读(2667)  评论(0编辑  收藏  举报