欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

PHP Non-blocking fopen, file_get_contents using stream_set_blocking

shiping1 的头像
function call_url($url) {
    // Call the url and return immediately with the length of the data read.
    // Useful for firing off scripts by calling a url.
 
    $fp = fopen($url, 'r');
    stream_set_blocking($fp, 0); // 0 => non-blocking mode
    $data = fread($fp, 8192); // 1024 * 8 = 8192
    fclose($fp);
 
    // Return the amount of data read
    return strlen($data);
}


来自  https://www.darklaunch.com/2013/03/23/php-non-blocking-fopen-file-get-contents-using-stream-set-blocking
普通分类: