note 107667 added to function.curl-setopt
| From: | wonderfish+php at gmail dot com | Date: | Sat, 25 Feb 2012 00:23:01 +0000 |
| Subject: | note 107667 added to function.curl-setopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186344@lists.php.net to get a copy of this message | ||
As of at least PHP 5.3.9, if you are continuing to use a cURL session handle after downloading a
file and closing the file handle, you will need to change CURLOPT_FILE back to stdout, and cannot
count simply on a side effect of CURLOPT_RETURNTRANSFER to do so, even if you are setting it. For
example:
$ch = curl_init();
$fh = fopen('/path/to/stored/file/example_file.dat', 'w');
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_URL, 'http://example.com/example_file.dat');
curl_exec($ch);
fflush($fh);
fclose($fh);
//must reset cURL file handle. Not doing so will cause a warning to be
//thrown and for cURL to default to output regardless
//for our example, we'll set return transfer.
curl_setopt($ch, CURLOPT_FILE, fopen('php://stdout', 'w'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, 'http://example2.com/index.html');
$html = curl_exec($ch); //this will now work
----
Server IP: 208.69.120.55
Probable Submitter: 70.167.158.178
----
Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php
Edit -- https://master.php.net/note/edit/107667
Del: integrated -- https://master.php.net/note/delete/107667/integrated
Del: useless -- https://master.php.net/note/delete/107667/useless
Del: bad code -- https://master.php.net/note/delete/107667/bad+code
Del: spam -- https://master.php.net/note/delete/107667/spam
Del: non-english -- https://master.php.net/note/delete/107667/non-english
Del: in docs -- https://master.php.net/note/delete/107667/in+docs
Del: other reasons-- https://master.php.net/note/delete/107667
Reject -- https://master.php.net/note/reject/107667
Search -- https://master.php.net/manage/user-notes.php