怎么设置file_get_contants()超时时间

如何设置file_get_contants()超时时间
用flie_get_contents获得一个网页的内容,如果网速很慢或下载这个页面需要很长的时间,就会经常超时,发出[function.file-get-contents]: failed to open stream: HTTP request failed! 错误。即使设置php.ini中的执行超时或者在代码中加入set_limit_time函数延长超时时间也无济于事。Google一下,找到了解决方法,需要在file_get_contents的参数中进行超时的设置,代码如下:
===========================================
// Create the stream context
$context = stream_context_create(array(
     'http' => array(
      'timeout' => 3000 //超时时间,单位为秒
     )
)); 
// Fetch the URL's contents
$contents = file_get_contents('http://sample.com', 0, $context);


这样就可以解决file_get_contents()函数的超时问题