ID:               49178
 Updated by:       j...@php.net
 Reported By:      moricio at gmail dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         cURL related
 Operating System: Windows 2003 Server SP2
 PHP Version:      5.2.10
 New Comment:

Please try using this snapshot:

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

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




Previous Comments:
------------------------------------------------------------------------

[2009-08-06 12:21:03] 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.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49178&edit=1

Reply via email to