#48870 [Opn->Csd]: File is missing 2048 bytes after fclose. When script ends the file is complete
| From: | iliaa@php.net | Date: | Thu, 09 Jul 2009 16:42:10 +0000 |
| Subject: | #48870 [Opn->Csd]: File is missing 2048 bytes after fclose. When script ends the file is complete | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-139535@lists.php.net to get a copy of this message | ||
ID: 48870
Updated by: iliaa@php.net
Reported By: lorenz dot werner at michel-consulting dot de
-Status: Open
+Status: Closed
Bug Type: Unknown/Other Function
Operating System: gentoo
PHP Version: 5.2.10
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2009-07-09 15:15:18] lorenz dot werner at michel-consulting dot de
Description:
------------
Since I upgraded to PHP 5.2.10 I have got an problem with files not
beiing completly written. Exactly 2048 bytes are missing while the
script is running. Even after fclose it is not completley written.
If I open the file for reading again and then close it again the file
is complete. But that can't be correct... or is it?
Reproduce code:
---------------
$fh = fopen($pdf_tarfile, "wb");
$ch = curl_init(PDF_SERVICE_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_exec($ch);
$return_code = curl_errno($ch);
if( $return_code ) {
trigger_error('curl returned error ' . $return_code . ': ' .
curl_error($ch), E_USER_ERROR);
return false;
}
curl_close($ch);
fclose($fh);
// It only works with this workaround
{
$fh = fopen($pdf_tarfile, "rb");
fclose($fh);
}
$cmd = 'tar'
. ' -x' // extract
. ' -f ' . escapeshellarg($pdf_tarfile) // this file
. ' -C ' . escapeshellarg($path); // into this directory
$stdout = array();
exec($cmd . ' 2>&1', $stdout, $return_code);
if ($return_code) {
trigger_error('tar returned error ' . $return_code . ': ' .
implode("\n", $stdout), E_USER_ERROR);
return false;
}
Expected result:
----------------
Correctly unpacked tar archive.
Actual result:
--------------
Tar fails to unpack the file because it is missing the last 2048
Bytes.
If I run the command manually after the script is finished, the file
can be unpacked without any problem at all.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48870&edit=1