> B. reading a byte at a time (that's how it was done previously). Well, actually, that is not the case. Since PHP 3.0.something, PHP used a socket buffering system for reading data from the network. Since then, no single byte reads were necessary.
Watch PHP 4.2 fgets'ing from the network: select(4, [3], NULL, NULL, NULL) = 1 (in [3]) recv(3, "+OK Cubic Circle\'s v1.31 1998/05"..., 8192, 0) = 77 select(4, [3], NULL, NULL, NULL) = 1 (in [3]) recv(3, "+OK uasdsaddsasd select"..., 8192, 0) = 1440 select(4, [3], NULL, NULL, NULL) = 1 (in [3]) recv(3, "\r\n SPAM: so you can recognise o"..., 8192, 0) = 678 select(4, [3], NULL, NULL, NULL) = 1 (in [3]) recv(3, "as an exclamation mark\r\n SPAM: "..., 8192, 0) = 367 > I'd like to investigate A because one might expect it to be more efficient. > In the interests of getting this done before we branch, making B happen > is probably the best option for now. Socket IO works differently than file IO. A read() from a socket returns once data is available, even if it is less than requested. In file IO, this case only happens, if you are at the end of the file. In socket IO, this will happen all the time. The stream_gets function had broken semantics. It used: Read data, consume data, repeat. However, with sockets, you cannot always read more data, even with blocking (think of an exchange of messages). The semantics have been improved to this now: Consume data, read data, repeat. This is also more efficient for the average case -- usually, the buffer will contain more complete lines, so it is faster to immediately look for a EOL, rather than reading new data unconditionally. stream_gets still has the problem that it is not fault tolerant. If the underlying stream dies, it will loop forever. This needs to be fixed, of course (grep for XXX). I also added an optional third exit condition to php_stream_fill_read_buffer. Previously, it stopped when - it had read the specified amount of data - an error occured Remember that socket IO usually returns less data than requested. As such, it must be possible to leave that function early. If the stream ops indicate that this third condition is valid, the function will return after the first successful read. - Sascha -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php