From: pavcio at 4lo dot bytom dot pl
Operating system: GNU/Linux 2.6.3
PHP version: 5CVS-2004-03-07 (dev)
PHP Bug Type: Filesystem function related
Bug description: fseek() causes PHP to hang on fwrite()
Description:
------------
I`ve noticed that fwrite() function hangs when it copies data from a file
to a pipe and fseek() has been called before it. See the code for
details.
My system:
- GNU/Linux Slackware-current on 2.6.3 kernel
- GCC 3.3.2
- glibc 2.3.2
- PHP versions tested: 5.0b4 and php5-200403071430
Reproduce code:
---------------
#!/usr/local/bin/php
<?php
$mfp = fopen(tempnam('/tmp', 'test'), 'w+');
for($i=0; $i < 1024; $i++) $kilobyte .= "A";
for($i=0; $i < 100; $i++) fwrite($mfp, $kilobyte);
$process = proc_open('/bin/cat', array(0 => array('pipe', 'r'), 1 =>
array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
fseek($mfp, 0);
while( TRUE ) {
$data = fread($mfp, 65536);
if( strlen($data) == 0 ) break;
fwrite($pipes[0], $data);
}
proc_close($process);
?>
Expected result:
----------------
Try to guess ;-).
Actual result:
--------------
Here is the end of strace dump:
(...cut...)
pipe([7, 8]) = 0
pipe([9, 10]) = 0
pipe([11, 12]) = 0
fork() = 16951
close(7) = 0
(,,,cut...)
lseek(3, 0, SEEK_SET) = 0
(...cut...)
write(8, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 8192) = 8192
write(8, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 8192) = 8192
write(8, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 8192) = 8192
write(8, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"..., 8192 <unfinished ...>
(here PHP hangs)
--
Edit bug report at http://bugs.php.net/?id=27518&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27518&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27518&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27518&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27518&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27518&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27518&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27518&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27518&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27518&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27518&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27518&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27518&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27518&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27518&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27518&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27518&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27518&r=float