amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.
https://amphp.org/byte-stream
MIT License
363 stars 31 forks source link

Add async readline/echo and add composer commands #63

Closed danog closed 9 months ago

bwoebi commented 5 years ago

Thanks, I was missing something akin to readLine just yesterday (just on a TCP socket to be used via telnet) ... But there's a catch: you are throwing away everything but the first line.

:-/

This is just a bit stupid due to that we have absolutely no buffering in out ResourceOutputStream. Is just sort of ... too primitive. Even on the kernel level you have the possibility to peek at the input stream and decide how much you want to consume (recv(MSG_PEEK)). But here this is not trivially possible.

It feels to me that there is fundamental functionality lacking here.

danog commented 5 years ago

Actually, I'm not throwing away anything because the other lines are being buffered in a static variable that persists after the function exits. I, too, encountered some issues when working with non-file AMP streams, which is why I created my own incremental async stream APIs, with buffered wrappers, hashing proxies, generic proxies. I intend to separate the stream and loop APIs of MadelineProto soon, so you can use them without including the entire project.

In the meantime you can try fiddling around with them if you like.

kelunik commented 5 years ago

@bwoebi I don't think these need to be on the basic interface. While they're sometimes needed, they can be provided by wrappers.

kelunik commented 5 years ago

We could include an implementation similar to https://github.com/kelunik/streaming-json/blob/c8b5bb9f65c67c0ca1fd2771ef00332c4c8ffe93/src/StreamingJsonParser.php, which doesn't do the JSON decoding and allows for customization of the line ending.

danog commented 4 years ago

Ping?

kelunik commented 9 months ago

This is something we see out of scope of this package, so I'm closing this. It hasn't received much attention in the last 4 years.