php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12022 limitations of php://stdout
Submitted: 2001-07-10 14:23 UTC Modified: 2001-09-10 17:08 UTC
From: noisefactor at netscape dot net Assigned:
Status: Closed Package: Output Control
PHP Version: 4.0.2 OS: linux
Private report: No CVE-ID: None
 [2001-07-10 14:23 UTC] noisefactor at netscape dot net
With perl cgi I can create a GZIP output stream
to a Java applet as follows:

print("Content-type: application/x-gzip\n\n");
my $gz=gzopen(\*STDOUT, "wb") || die("gasp!");   

however, the same technique seems to be impossible
with php://stdout.  i realize that i can open
a gzip'd stream as follows (note: i am using php 4.02):

gzopen("php://stdout","w");

however, there seems to be no way to get header fields
(uncompressed) to precede the gzip'd output.  this 
presents an unresolvable problem on the browser side,
because some browsers will assume that no data has been
sent if no header fields are received.

can the php://stdout mechanism be changed to allow me
to print uncompressed lines to stdout before the compressed
output begins?  am i missing something here?  i realize
that i can put zipped data into a file and use readfile()
to send it, and this actually does send all the header
fields as would be expected. however, this will cause
me unnecessary drive activity because i will have to modify
the files, which i had not wanted to do.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-06 23:21 UTC] sterling@php.net
use the header() function, btw, Perl is not php,
gzopen("php://stdout", "w") is not the same as the Perl example.
 [2001-09-08 20:16 UTC] noisefactor at netscape dot net
You may want to wait on closing that bug...

>   ID: 12022
>   Updated by: sterling
>   Old Status: Open
>   Status: Closed
>   Bug Type: Output Control
>   Operating System: linux
>   New Comment:
>
>   use the header() function, btw, Perl is not php,
>   gzopen("php://stdout", "w") is not the same as the Perl example.

With respect to Sterling's suggestion that I 
use header(), that was of course the _first_ thing
that I tried, but it did not work with (my PHP/4.0.2
running on Linux).  I'm not sure what point he is
trying to make about perl not being php.  I'm not
a perl fanatic trying to demonstrate the limitations
of php, I simply can't do what I want to do with php.

if you read the original bug report carefully, you
will see that the problem resides in not being able to
emit uncompressed headers before the compressed output,
at least when using php://stdout.  i have no problem when
i use the readfile() technique: the headers are uncompressed
and the content of the file can be g-zip.

andy

   
>Previous Comments:
>------------------------------------------------------------------------
>
>[2001-07-10 14:23:04] noisefactor@netscape.net
>
>With perl cgi I can create a GZIP output stream
>to a Java applet as follows:
>
>print("Content-type: application/x-gzip\n\n");
>my $gz=gzopen(\*STDOUT, "wb") || die("gasp!");   
>
>however, the same technique seems to be impossible
>with php://stdout.  i realize that i can open
>a gzip'd stream as follows (note: i am using php 4.02):
>
>gzopen("php://stdout","w");
>
>however, there seems to be no way to get header fields
>(uncompressed) to precede the gzip'd output.  this 
>presents an unresolvable problem on the browser side,
>because some browsers will assume that no data has been
>sent if no header fields are received.
>
>can the php://stdout mechanism be changed to allow me
>to print uncompressed lines to stdout before the compressed
>output begins?  am i missing something here?  i realize
>that i can put zipped data into a file and use readfile()
>to send it, and this actually does send all the header
>fields as would be expected. however, this will cause
>me unnecessary drive activity because i will have to modify
>the files, which i had not wanted to do.
>
>------------------------------------------------------------------------
>
>

 [2001-09-08 20:34 UTC] rasmus@php.net
What exactly is the issue here?  Why are you trying to open up stdout?  You can write gzip data directly without doing that.  For example:

<?
	Header("Content-type: application/x-gzip");
	echo gzencode("Hello World");
?>

This works just fine.  The headers are uncompressed, the content is compressed.  I don't see a bug here.  stdout only makes sense when running from the command line.  Which also works just fine, by the way:

<?
	Header("Content-type: application/x-gzip");
	$fp = gzopen("php://stdout", "w");
	gzputs ($fp, "Hello World");
?>

which when run from the command line produces:

X-Powered-By: PHP/4.0.7-dev
Content-type: application/x-gzip

?H????/?IV?J

Again, uncompressed headers, compressed data.
 [2001-09-09 14:57 UTC] noisefactor at netscape dot net
in order to demonstrate the problem that i'm 
experiencing, i've made a small tarball with 
rasmus's suggestion, and the java applet (simplified)
code that accepts the file-based gzip data, but 
doesn't work with the technique rasmus suggests.

since i'm using 4.0.2, i could only try one of his
suggestions (there was no gzencode in 4.0.2).

andy

http://artcontext.org/act/01/test.gz

PS successful execution of the applet simply dumps
"Hello World" into the monitor/console.
 [2001-09-09 15:07 UTC] noisefactor at netscape dot net
incidently, i've used telnet to port 80 to 
monitor the output of the .php script that feeds 
the applet, and it's clear that the problem is
on the php end.  having said that, i have no
idea if this is normal 4.0.2 behavior or if it
will not be reproduced on other systems.

results of these tests are below...

#
# First using the php://stdout technique,
# exactly as suggested by rasmus
#
telnet artcontext.org 80 
Trying 160.79.162.111...
Connected to artcontext.org.
Escape character is '^]'.
GET /act/01/test/makeencoded.php HTTP/1.0

HTTP/1.1 200 OK
Date: Sun, 09 Sep 2001 19:21:14 GMT
Server: Apache/1.3.12 (Unix) ApacheJServ/1.1.2 PHP/4.0.2
X-Powered-By: PHP/4.0.2
Connection: close
Content-Type: application/x-gzip

Connection closed by foreign host.
#
# connection closes, no output
#

#
# next using the readfile technique --
# 
telnet artcontext.org 80 
Trying 160.79.162.111...
Connected to artcontext.org.
Escape character is '^]'.
GET /act/01/test/makeencoded.php HTTP/1.0

HTTP/1.1 200 OK
Date: Sun, 09 Sep 2001 19:21:31 GMT
Server: Apache/1.3.12 (Unix) ApacheJServ/1.1.2 PHP/4.0.2
X-Powered-By: PHP/4.0.2
Connection: close
Content-Type: application/x-gzip

(some garbage compression text appears here)
 [2001-09-10 17:08 UTC] sniper@php.net
First update to more recent version before submiting any 
bug reports. 4.0.2 is just too old.

--Jani

 [2003-09-01 02:52 UTC] learn at university dot com
From what I have read, the problem is in your theory.
Do you understand what the difference between a browser window and output to screen is?
This will go a long way in identifying why and when you should use certain approaches.
Just because you can do it in one language doesn't mean it's a correct method.
 [2004-09-25 00:00 UTC] ash27_75 at yahoo dot com
i have a file .dat which is 3.5 GiG .when im trying to gzip the file i'm getting an error as 'unknown error'.
Does the size of the file matters for gzip command,if yes suggest me a better way to zip a big file.
How does compress differ from gzip.
thanks
Ashok
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Sep 25 20:01:24 2020 UTC