That will work, even if the fread doesn't read all the data in one go, it will still call the function on the next tick. With php-uv, it will not. It appears that it has to wait until new data hits the socket. This means that a programmer would have to know the maximum buffers of the socket in the target environment, or risk missing the tail end of a transaction.

This comment has been minimized.

edited

The reason here is that the default chunk size of PHP is 8192. If you read less than that, PHP may have locally buffered data, which just stream_select() is aware of. (Other backends like libevent aren't aware of it either.)
If you use any multiple of 8192 in fread, you won't occur such an issue.Or you have to explicitly lower the stream chunk size for that stream via stream_set_chunk_size().

It's not per se a bug, but one does have to be aware of that behavior and needs to be documented accordingly.

p.s.: In Amp v2.0 we currently recommend using \AsyncInterop\Loop::onReadable() directly. (but that may change with async-interop/event-loop#149)