file_get_contents timeout cause cpu 100% solution

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

Can set a timeout, the function itself can be encapsulated

Reproduced in: https: //www.cnblogs.com/in-loading/archive/2012/07/25/2607783.html

Guess you like

Origin blog.csdn.net/weixin_34375251/article/details/93700343