当前位置:编程学习 > php >>

php里面给file_get_contents函数设置超时 防止卡死网站

file_get_contents 超时导致cpu 100%的解决方案 发表回复

设置一个超时时间就可以,可以自行封装函数

<?php 
$ctx = stream_context_create(array
   'http' => array
       'timeout' => 1 //设置一个超时时间,单位为秒 
       
   
); 
file_get_contents("http://example.com/", 0, $ctx); 
?>


CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,