curl: How to limit size of GET?

后端 未结 5 759
逝去的感伤
逝去的感伤 2020-12-11 22:03

I want to retrieve the first 10k bytes from a URL with curl (using PHP in my case). Is there a way to specify this? I thought CURLOPT_BUFFERSIZE would do this, but it just a

5条回答
  •  粉色の甜心
    2020-12-11 22:19

    If you use fread instead of curl, although I prefer curl, you can specify the size of the data you want to receive, for example:

    $fp = @fopen($url, "r") ;
    
    $data = "" ;
    if($fp) {
        while (!feof($fp)) {
            $data .= fread($fp, $size) ;
    }
    fclose($fp) ;
    

提交回复
热议问题