Make cURL write data as it receives it

前端 未结 4 1751
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 02:58

I have the following php code which I found here:

function download_xml()
{
    $url = \'http://tv.sygko.net/tv.xml\';

    $ch = curl_init($url);
    $timeo         


        
4条回答
  •  我在风中等你
    2021-01-07 03:40

    There's an option called CURELOPT_FILE that allows you to specify a file handler that curl should write to. I'm pretty sure it will do "right" thing and "write" as it reads, avoiding your memory problem

    $file = fopen('test.txt', 'w'); //<--------- file handler
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'http://example.com');
    curl_setopt($ch, CURLOPT_FAILONERROR,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_FILE, $file);   //<------- this is your magic line
    curl_exec($ch); 
    curl_close($ch);
    fclose($file);
    

提交回复
热议问题