php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49178 Incomplete file downloads
Submitted: 2009-08-06 12:21 UTC Modified: 2009-08-14 01:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: moricio at gmail dot com Assigned:
Status: No Feedback Package: cURL related
PHP Version: 5.2.10 OS: Windows 2003 Server SP2
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: moricio at gmail dot com
New email:
PHP Version: OS:

 

 [2009-08-06 12:21 UTC] moricio at gmail dot com
Description:
------------
Hi.

I have a PHP app where I generate a PDF file, using jasperreports, and 
then mail this file to a subscriber. I use curl and the CURLOPT_FILE 
option to get the pdf file. As soon as I finish getting the file, it 
reports a size that is always an exact multiple of 4Kbytes, even when 
the file is bigger than what PHP reports.


Reproduce code:
---------------
Code with error is ...
--
<?php
$ch = curl_init("http://www.google.com");
$tmpfname = tempnam(sys_get_temp_dir(), "IPV");
$fpOutput = fopen($tmpfname, "wb");

curl_setopt($ch, CURLOPT_FILE, $fpOutput);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fpOutput);
echo "filesize: $tmpfname: " . filesize($tmpfname) . "\n";
?>

--

Code without error is ...
--
<?php
$tmpfname = tempnam(sys_get_temp_dir(), "IPV");
$fpOutput = fopen($tmpfname, "wb");

$ch = curl_init("http://www.google.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
curl_exec($ch);
curl_close($ch);

fclose($fpOutput);

echo "filesize: $tmpfname: " . filesize($tmpfname) . "\n";
die();

function read_body($ch, $string)
{
	global $fpOutput;

	$length = strlen($string);
	if (fwrite($fpOutput, $string) === FALSE) {
		echo "Cannot write to file";
		die();
	}
	return $length;
}
?>


Expected result:
----------------
The second piece of code reported in this bug report gives the correct 
file size.

The first piece of code saves the file with the correct size but doesn't 
report it correctly.

This was not happening until I upgraded to PHP 5.2.10 from a previous 
version that I don't remember. :(

Hope you can find inside what is going on.

Best regards and thanks for a great piece of software.

Mauricio Ramirez


Actual result:
--------------
The first piece of code reports 4096 bytes for the google.com page.

The second piece of code reports (today!) 6672 bytes which is the right 
size.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-06 13:19 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-08-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-10-11 08:49 UTC] phpspam at ethaniel dot com
I confirm this on PHP 5.2.10 (cli) running on Freebsd 7.2.
 [2009-10-11 09:43 UTC] phpspam at ethaniel dot com
This has been fixed in 5.2.11
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 03:01:28 2024 UTC