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

curl-and-php

Re: help with PUT and CURLOPT_READFUNCTION

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 1 May 2008 22:40:31 +0200 (CEST)

On Thu, 1 May 2008, James Goddard wrote:

> I can successfully PUT a file using CURLOPT_PUT, CURLOPT_INFILE, and
> CURLOPT_INFILESIZE. However, for large files ( > ~100MB) my machine runs out
> of memory so I want to be able to "stream" the file to the webserver
> (instead of storing it in memory and then sending) via CURLOPT_READFUNCTION.

I'm sorry, but I don't buy this explanation. libcurl itself only supports HTTP
PUT by streaming the upload, and I'm quite sure the PHP layer doesn't add any
major magic to that. Thus, the size of the PUT upload has no relevance, it
always takes roughly the same amount of memory!

> Unfortunately, I can't get this to work and cannot find any working examples
> online.

I don't know enough PHP/CURL to tell you exactly why.

> curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');

This is not neccesary. CURLOPT_UPLOAD with HTTP implies PUT.

> $request_headers[] = 'Content-Length: '.$this->fileSize;

I advice you to never ever fiddle with the Content-Length: header yourself.
You only risk damaging things and libcurl always adds that header itself.

> $request_headers[] = "Transfer-Encoding: ";

There's really no reason to do this.

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-05-01