note 70123 added to function.curl-exec

From: Date: Wed, 04 Oct 2006 08:41:10 +0000
Subject: note 70123 added to function.curl-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-118020@lists.php.net to get a copy of this message
Be careful when using curl_exec() and the CURLOPT_RETURNTRANSFER option. According to the manual and assorted documentation: Set CURLOPT_RETURNTRANSFER to TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. When retrieving a document with no content (ie. 0 byte file), curl_exec() will return bool(true), not an empty string. I've not seen any mention of this in the manual. Example code to reproduce this: <?php // fictional URL to an existing file with no data in it (ie. 0 byte file) $url = 'http://www.example.com/empty_file.txt'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); // execute and return string (this should be an empty string '') $str = curl_exec($curl); curl_close($curl); // the value of $str is actually bool(true), not empty string '' var_dump($str); ?> ---- Server IP: 83.138.144.80 Probable Submitter: 62.3.216.18 ---- Manual Page -- http://www.php.net/manual/en/function.curl-exec.php Edit -- https://master.php.net/note/edit/70123 Del: integrated -- https://master.php.net/note/delete/70123/integrated Del: useless -- https://master.php.net/note/delete/70123/useless Del: bad code -- https://master.php.net/note/delete/70123/bad+code Del: spam -- https://master.php.net/note/delete/70123/spam Del: non-english -- https://master.php.net/note/delete/70123/non-english Del: in docs -- https://master.php.net/note/delete/70123/in+docs Del: other reasons-- https://master.php.net/note/delete/70123 Reject -- https://master.php.net/note/reject/70123 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118020) next »