From: moricio at gmail dot com Operating system: Windows 2003 Server SP2 PHP version: 5.2.10 PHP Bug Type: cURL related Bug description: Incomplete file downloads
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 bug report at http://bugs.php.net/?id=49178&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49178&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49178&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49178&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49178&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49178&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49178&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49178&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49178&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49178&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49178&r=support Expected behavior: http://bugs.php.net/fix.php?id=49178&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49178&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49178&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49178&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49178&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49178&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49178&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49178&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49178&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49178&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49178&r=mysqlcfg