我的一个程序会发起一个http请求到另一个项目,用的file_get_content函数,我需要保证请求发出了,但是不需要返回结果,我可以设置file_get_content的超时时间为1秒吗?因为目前设置的3秒,很多慢请求
我的一个程序会发起一个http请求到另一个项目,用的file_get_content函数,我需要保证请求发出了,但是不需要返回结果,我可以设置file_get_content的超时时间为1秒吗?因为目前设置的3秒,很多慢请求
两个办法
1.直接临时修改ini配置
ini_set('default_socket_timeout', 900);//单位秒
2.这个函数也是有其他参数的
$ctx = stream_context_create(array('http'=>
array(
'timeout' => 1200,//单位秒
)
));
echo file_get_contents('http://example.com/', false, $ctx);
4 回答968 阅读
1 回答643 阅读✓ 已解决
2 回答617 阅读
603 阅读
file_get_contents()是专门用来获取文件数据流的,要么拿到,要么报错,你的目的如果只是想要请求,试试curl,可以设置请求时长