PHP中file_get_contents($url)的超时处理
2017-07-25 18:12
609 查看
PHP中
file_get_contents函数的作用是获取一个 URL 的返回内容。如果是url响应速度慢,或者网络等因素,会造成等待时间较长的情况。只需设置一下
file_get_contents函数的超时时间即可解决。示例代码如下:
<?php //设置超时参数 $opts=array( "http"=>array( "method"=>"GET", "timeout"=>3 ), ); ////创建数据流上下文 $context = stream_context_create($opts); //$url请求的地址,例如: $result =file_get_contents($url, false, $context); // 打印结果 print_r($result); ?>
相关文章推荐
- 深入php函数file_get_contents超时处理的方法详解
- 深入php函数file_get_contents超时处理的方法详解
- stream_context_create解决file_get_contents超时处理
- stream_context_create解决file_get_contents超时处理
- php函数file_get_contents超时处理的方法(2013最新整理)
- file_get_contents超时处理
- file_get_contents的超时处理(膘叔)
- file_get_contents的超时处理
- php使用Url读取文件的内容及file_get_contents用法
- 执行、获取远程代码返回:file_get_contents 超时处理的问题详解
- file_get_contents的超时处理对连接超时无效
- PHP的file_get_contents设置超时
- 执行、获取远程代码返回:file_get_contents 超时处理的问题详解
- PHP的file_get_contents设置超时
- 执行、获取远程代码返回:file_get_contents 超时处理
- php 两种方法获取url内容 file_get_contents和curl
- stream_context_create解决file_get_contents超时处理
- file_get_contents 增加超时的时间限制
- 通过file_get_contents执行带参数的php
- file_get_contents("php://input", "r")实例介绍