php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72092 CURLOPT_FILE is rewinded depending on stream type
Submitted: 2016-04-24 06:41 UTC Modified: 2019-03-26 17:28 UTC
Votes:5
Avg. Score:2.6 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: bugs dot php dot net at ss dot st dot tc Assigned:
Status: Verified Package: cURL related
PHP Version: 7.0.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
30 - 7 = ?
Subscribe to this entry?

 
 [2016-04-24 06:41 UTC] bugs dot php dot net at ss dot st dot tc
Description:
------------
When using CURLOPT_FILE, file position indicator stays in the end when the handle is a temporary stream. However the indicator is rewinded to 0 when the handle is a regular file (which seems to be a wrong behaviour).

Tested in PHP 7.0.5 and 5.6.20.

Test script:
---------------
<?php

function test($filename) {
	echo $filename, PHP_EOL;
	$fh = fopen($filename, 'w');

	$curl = curl_init('http://php.net/');
	curl_setopt($curl, CURLOPT_FILE, $fh);
	curl_exec($curl);

	echo ' fstat size: ', fstat($fh)['size'], PHP_EOL;
	echo ' ftell: ', ftell($fh), PHP_EOL;
}

test('regular-file.tmp');
test('php://temp');


Expected result:
----------------
regular-file.tmp
 fstat size: 19371
 ftell: 19371
php://temp
 fstat size: 19371
 ftell: 19371


Actual result:
--------------
regular-file.tmp
 fstat size: 19371
 ftell: 0
php://temp
 fstat size: 19371
 ftell: 19371


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-03 15:49 UTC] vonubrog at gmail dot com
Same here with PHP 7.0.9 and 5.4.45. Such an annoying inconsistency :(
 [2019-03-26 16:29 UTC] mike@php.net
Probably fixable by upgrading internals to streams instead of stdio.

Related to Bug #76268 and Bug #70693
 [2019-03-26 17:28 UTC] mike@php.net
-Status: Open +Status: Verified
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC