Bug #53241 [Opn]: fopen(..., 'xb') and CURLOPT_FILE make cURL fail with: fopencookie failed
| From: | cataphract@php.net | Date: | Thu, 04 Nov 2010 18:55:42 +0000 |
| Subject: | Bug #53241 [Opn]: fopen(..., 'xb') and CURLOPT_FILE make cURL fail with: fopencookie failed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-155766@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53241&edit=1
ID: 53241
Updated by: cataphract@php.net
Reported by: Alexander dot Farber at gmail dot com
Summary: fopen(..., 'xb') and CURLOPT_FILE make cURL fail
with: fopencookie failed
Status: Open
Type: Bug
Package: cURL related
Operating System: CentOS 5.5 Linux
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cataphract
Block user comment: N
New Comment:
The problem is the cast to a FILE* pointer fails when the modes "x"/"c"
and variants are used.
I'll see what can be done.
Previous Comments:
------------------------------------------------------------------------
[2010-11-04 14:36:39] Alexander dot Farber at gmail dot com
Description:
------------
If I call:
$fh = fopen('/tmp/yahoo.html', 'xb');
$ch = curl_init('http://www.yahoo.com/');
curl_setopt($ch, CURLOPT_FILE, $fh);
then the last line will fail with the misleading fopencookie-message.
I need to use 'xb' and not 'wb', to ensure that just 1 script instance
writes into that file - please see more info here:
http://stackoverflow.com/questions/4096470/php-curl-curl-setopt-fopencookie-failed
Test script:
---------------
<?php
#phpinfo();
$fh = fopen('/tmp/yahoo.html', 'xb');
if ($fh) {
$ch = curl_init('http://www.yahoo.com/');
curl_setopt($ch, CURLOPT_FILE, $fh); # XXX the line 6
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT,
$_SERVER['HTTP_USER_AGENT']);
#curl_setopt($ch, CURLOPT_COOKIEJAR, '/dev/null');
#curl_setopt($ch, CURLOPT_COOKIEFILE, '/dev/null');
#curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
#curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
curl_exec($ch);
if(!curl_errno($ch)) {
$info = curl_getinfo($ch);
echo 'Took '.$info['total_time'] .
's to send a request to '.$info['url'];
}
curl_close($ch);
fclose($fh);
} else {
echo 'Can not open /tmp/yahoo.html';
}
?>
Expected result:
----------------
I expect the script create the file /tmp/yahoo.html on the 1st run and
put the downloaded content into it.
Actual result:
--------------
Nov 4 12:55:19 centos httpd: PHP Fatal error: curl_setopt() [<a
href='function.curl-setopt'>function.curl-setopt</a>]: fopencookie
failed in /var/www/html/proxy3.php on line 6
And the file is sero-sized:
afarber@centos:html> ls -alZ /tmp/yahoo.html
-rw-r--r-- apache apache user_u:object_r:httpd_tmp_t
/tmp/yahoo.html
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53241&edit=1