|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-03-07 16:39 UTC] wez@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 21:00:01 2025 UTC |
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)