|
From: <php...@li...> - 2010-02-09 17:07:03
|
Mark, you don't seem to understand the issue. 1. A GET request must be answered by the HTTP 1.1 server by either sending the Content-Length header or by sending the Transfer-Encoding: chunked header. 2. To send large responses efficiently, Transfer-Encoding: chunked is used. 3. The network buffer used by the PHP streams implementation reads data eagerly. If you fread($socket, 1024) and the network buffer already contains 24 bytes, PHP will try to read 1000 bytes nevertheless. 4. If you open a HTTP 1.0 connection to a HTTP server which cannot respond with a Content-Length header, the behaviour is implementation specific. It may send an error, send a raw byte stream or it may start playing nethack. 5. PHP running within Apache behaves exactly the same as PHP running within a JEE server or servlet engine. The only difference is that Java prints a stack trace when the hanging PHP instance is killed, while Apache silently kills it with SIGCHILD. You don't have many choices to implement your "stream download". Either you use HTTP/1.1 chunked connections, or you will have to deal with an implementation-specific behaviour of both, the HTTP server (#4) *and* PHP (#3). Since the PHP streams implementation cannot handle raw byte streams which don't have an explicit length (either Content-Length or the length from each "chunked" header), you cannot use PHP fread --- your "fgets()" is bogus because you do not and cannot distinguish between the \r\n from the data and the \r\n used to split the packets, so your download is garbage anyway --- to receive the data, unless the remote server shuts down the connection at the end of the transfer, so that PHP's fread (or fgets) doesn't try to fill its network buffer over the end of the data. If you want to discuss this issue further, please use the PHP mailing list instead. Regards, Jost Bökemeier |