控制file

    技术2025-12-20  8

    最近发现使用file_get_content调取评论数据的时候会出现超时现象

    而该函数本身不可配置超时时间

    找来如下方法

        $opts = array(         'http'=>array(         'method'=>"get",         'timeout'=>10,         )     );     $context = stream_context_create($opts);     $tmp = file_get_contents($url,false,$context);     fpassthru($fp);

    思路是利用stream_context_create配置http请求,在取数据的时候就可以限制超时

    最后用fpassthru($fp); 不是很懂,这里并没有$fp啊

    最新回复(0)