#27518 [Opn->Bgs]: fseek() causes PHP to hang on fwrite()

From: Date: Sun, 07 Mar 2004 21:39:56 +0000
Subject: #27518 [Opn->Bgs]: fseek() causes PHP to hang on fwrite()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56053@lists.php.net to get a copy of this message
ID: 27518 Updated by: wez@php.net Reported By: pavcio at 4lo dot bytom dot pl -Status: Open +Status: Bogus Bug Type: Filesystem function related Operating System: GNU/Linux 2.6.3 PHP Version: 5CVS-2004-03-07 (dev) New Comment: You are filling up the pipes and never consuming the data from its output. Not a bug in php at all, but your script. Use a smaller size chunk when writing to the pipe, and read the data from your output pipe. Also, *PLEASE* fill in the bug report correctly; if you'd filled in the expected output in the first instance I could have diagnosed your broken code just by reading it. Previous Comments: ------------------------------------------------------------------------ [2004-03-07 12:19:18] pavcio at 4lo dot bytom dot pl 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 this bug report at http://bugs.php.net/?id=27518&edit=1

« previous php.bugs (#56053) next »