cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Server memory usage

From: Leonardo <leobasilio_at_gmail.com>
Date: Sat, 7 Feb 2009 00:28:25 -0200

Hi, everybody. Sorry if there's another post about this problem, but I did
some googling and couldn't find an answer. I have a php code that I use for
downloading files with curl. Everything would be fine if it didn't consume
so much memory. It looks like its buffer is not being free or something like
that, even though ob_flush is called. Here's a piece of the code:

$c = curl_init($LOCATION);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, false);
curl_setopt($c, CURLOPT_WRITEFUNCTION, 'foo');
curl_setopt($c, CURLOPT_BUFFERSIZE, 102400); // 100KB buffer size

function foo($c, $data){

    @ob_flush();

    // does whatever it does

    return strlen($data);

}

curl_exec($c);

curl_close($c);

Every time the code is run, the memory usage goes up quickly. Without
ob_flush, the browser starts getting the response only once the download is
completed. That's ok. With ob_flush, the response is sent as curl gets it,
but I think curl does not throw away the data that was already sent to the
browser and keeps storing it at memory. Does it make any sense? How can I
fix it? Thank you.

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-02-07