php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48733 CURLOPT_WRITEHEADER warns "the provided file handle is not writable"
Submitted: 2009-06-30 10:05 UTC Modified: 2009-07-02 13:42 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: sta at netimage dot dk Assigned: iliaa (profile)
Status: Closed Package: cURL related
PHP Version: 5.2.10 OS: FreeBSD 7.1
Private report: No CVE-ID: None
 [2009-06-30 10:05 UTC] sta at netimage dot dk
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-02 13:42 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC