#43468 [Com]: Curl doesn't handle php://memory stream

From: Date: Wed, 11 Feb 2009 02:13:44 +0000
Subject: #43468 [Com]: Curl doesn't handle php://memory stream
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-133699@lists.php.net to get a copy of this message
ID: 43468 Comment by: davirtavares at gmail dot com Reported By: peter at petersmit dot eu Status: No Feedback Bug Type: cURL related Operating System: Ubuntu Linux Gutsy Gibbon PHP Version: 5.2.6 New Comment: The final workaround I currently use is setting both CURLOPT_WRITEFUNCTION and CURLOPT_READFUNCTION options. So I can write and read using the memory stream, even being unsupported by CURL: // open the memory stream (currently using "temp" but it should works with "memory" stream as well): $temp = fopen('php://temp', 'rb+'); function cb_curl_write($ch, $data) { global $temp; return fwrite($temp, $data); } function cb_curl_read($ch, $fd, $size) { global $temp; return fread($temp, $size); } // put some data into the stream: // TODO rewind($temp); // get the content size of the stream $input_stat = fstat($temp); $input_size = $input_stat['size']; $ch = curl_init('http://www.php.net/'); curl_setopt($ch, CURLOPT_PUT, true); curl_setopt($ch, CURLOPT_INFILESIZE, $input_size); curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'cb_curl_write'); curl_setopt($ch, CURLOPT_READFUNCTION, 'cb_curl_read'); curl_exec($ch); curl_close($ch); Previous Comments: ------------------------------------------------------------------------ [2009-01-29 02:14:06] davirtavares at gmail dot com Well, I just discovered that I can use fstat to get the size of a stream (even memory ones). Follows the test case: $fi = fopen('php://temp', 'rb+'); // fill the $fi stream with some data $input_stat = fstat($fi); $input_size = $input_stat['size']; curl_setopt($ch, CURLOPT_PUT, true); curl_setopt($ch, CURLOPT_INFILE, $fi); curl_setopt($ch, CURLOPT_INFILESIZE, $input_size); curl_exec($ch); Davi ------------------------------------------------------------------------ [2009-01-29 00:06:27] davirtavares at gmail dot com I got the same problem. I'm trying to submit data by PUT request and aparently memory streams don't work for just a single CURL option: curl_setopt($ch, CURLOPT_INFILESIZE, $input_size); Aparently some servers don't like when you submit data w/o the content-size. But... how to obtain the size of a memory stream? Davi ------------------------------------------------------------------------ [2008-12-18 01:00:00] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2008-12-11 02:41:48] dan dot hitt at gmail dot com I built again, and tried Peter's test again, and it failed again. But note that with either the build from today or yesterday it gives partial results for the wikipedia (it looks like it loses the last 497 characters). My configuration command is: ./configure --prefix=/home/danh/staging/php/2008_12_11_a --with-curl=/home/danh/staging/curl/2008_09_12 dan ------------------------------------------------------------------------ [2008-12-11 00:06:56] jani@php.net Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://windows.php.net/snapshots/ And provide the full configure line you used if the snapshot does not work. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/43468 -- Edit this bug report at http://bugs.php.net/?id=43468&edit=1

« previous php.bugs (#133699) next »