php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60535 php ends prematurely when reading from pipe
Submitted: 2011-12-15 15:26 UTC Modified: 2011-12-22 13:02 UTC
From: andreas_nordal_4 at hotmail dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: 5.3.8 OS: Windows 7 Enterprise SP1
Private report: No CVE-ID: None
 [2011-12-15 15:26 UTC] andreas_nordal_4 at hotmail dot com
Description:
------------
I am using the command-line `php` program in a bash script to generate a html file, like so:

# stage 1:
intermediate="$(php doc.php)"
# stage 2:
echo "$intermediate" | php > doc.html

Stage 2 doesn't work on Windows when doc.html gets big (observed sizes in bytes: 42033, 42079, 41989, 42856, 41924). Php just ends prematurely, without printing any error message to either standard error or out. The size of doc.html is consistent every time I try, but depends on, at least, the amount of static content (between ?> an, d <?) in $intermediate. The output always ends on a linefeed.

I also tried piping a pure html file of size 32597 (https://bugs.php.net/report.php) through php in similar fashion. This time, the output size was inconsistent. Mostly, it was truncated to 16423, sometimes not truncated, and once truncated to 8945.

Absurdly, this workaround works:
echo "$intermediate" | tee intermediate.php; cat intermediate.php | php > doc.html
The fact that tee is able to read everything from the same pipe, and php succeeds when its input comes from cat, makes me think this is php's fault (likely a timing issue) rather than bash. Of course, I might be wrong.

The same bash script works flawlessly on Linux. I have php version 5.3.8 both on Linux and Windows. The installer I used on Windows is named "php-5.3.8-Win32-VC9-x86.msi", has filesize 40300544 and md5sum 2eacd59df8d6b46d5538f2935514d77b.

This bug might explain bug 26271 (which deals with named pipes):
In his case, I can imagine that the writer would hang if the reader ends prematurely. Just speculating.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-16 16:30 UTC] cataphract@php.net
Maybe this is the same as bug #52911. Can you check it out? If so, this should be marked a duplicate.
 [2011-12-20 14:42 UTC] andreas_nordal_4 at hotmail dot com
I think I can reproduce bug 26271.

I had to modify the testcase, by setting the second argument of str_repeat 10 times higher, and adding the suggested sleep.
I don't get a parse error, but the amount of sleep after proc_open determines the returnvalue of fwrite. If not sleeping, I always get 8192 no matter the argument to str_repeat.
 [2011-12-22 13:02 UTC] cataphract@php.net
-Status: Open +Status: Duplicate
 [2011-12-22 13:02 UTC] cataphract@php.net
I'm marking this a dup at bug #52911, then.

Thanks for the report.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 08 06:01:25 2020 UTC