#48733 [NEW]: CURLOPT_WRITEHEADER warns "the provided file handle is not writable"

[email protected] ("sta at netimage dot dk")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             sta at netimage dot dk
Operating system: FreeBSD 7.1
PHP version:      5.2.10
PHP Bug Type:     cURL related
Bug description:  CURLOPT_WRITEHEADER warns "the provided file handle is not writable"

Description:
------------
I have a script that temporarily stores the headers in a file created by
$fp_header = tmpfile().
It worked perfectly until upgrading from 5.2.9.
Now curl_setopt($ch, CURLOPT_WRITEHEADER, $fp_header)
triggers a warning:
  Warning: curl_setopt(): the provided file handle is not writable in
/curl.php on line x



Reproduce code:
---------------
<?php
ini_set('display_errors',1); error_reporting(E_ALL | E_STRICT);
$ch = curl_init('http://dk.php.net/');
if ( ! ($fp_header = tmpfile())) { die('File not created'); }
curl_setopt($ch, CURLOPT_WRITEHEADER,		$fp_header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,	true);
curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); echo "HTTP
$http_code\n";
curl_close($ch);
echo "Headers ===>\n";
rewind($fp_header); echo stream_get_contents($fp_header);
echo "<=== Headers\n";
rewind($fp_header); ftruncate($fp_header, 0);
fwrite($fp_header, "The file is writeable\n");
echo "My test ===>\n";
rewind($fp_header); echo stream_get_contents($fp_header);
echo "<=== My test\n";
fclose($fp_header);

Expected result:
----------------
Output from PHP 5.2.9 (run from command line):
HTTP 200
Headers ===>
HTTP/1.1 200 OK
Date: Tue, 30 Jun 2009 09:51:08 GMT
Server: Apache/2.2.9 (FreeBSD) DAV/2 PHP/5.2.8 with Suhosin-Patch
X-Powered-By: PHP/5.2.8
Last-Modified: Tue, 30 Jun 2009 10:37:51 GMT
Content-language: en
Set-Cookie: COUNTRY=DNK%2C193.162.142.106; expires=Tue, 07-Jul-2009
09:51:08 GMT; path=/; domain=.php.net
X-PHP-QUESTION: I wonder if anyone will ever notice this
Transfer-Encoding: chunked
Content-Type: text/html;charset=utf-8

<=== Headers
My test ===>
The file is writeable
<=== My test


Actual result:
--------------
Output from PHP 5.2.10 (run from command line):
PHP Warning:  curl_setopt(): the provided file handle is not writable in
/curl.php on line 5

Warning: curl_setopt(): the provided file handle is not writable in
/curl.php on line 5
HTTP 200
Headers ===>
<=== Headers
My test ===>
The file is writeable
<=== My test


-- 
Edit bug report at http://bugs.php.net/?id=48733&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        http://bugs.php.net/fix.php?id=48733&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        http://bugs.php.net/fix.php?id=48733&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        http://bugs.php.net/fix.php?id=48733&r=trysnapshot60
Fixed in CVS:                        http://bugs.php.net/fix.php?id=48733&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48733&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=48733&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=48733&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=48733&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=48733&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=48733&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=48733&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=48733&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=48733&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=48733&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48733&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48733&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=48733&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=48733&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=48733&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=48733&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=48733&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.