Comments (16)
fwrite
emits a warning when attempting a write and the buffer is full. I'm not aware of any way to avoid that problem.
Do we need the feof
check at all? It seems unreliable at best, which is why we started counting empty writes in the first place.
from byte-stream.
It seems like this works pretty well:
set_error_handler(function ($errno, $msg, $file, $line) {
// Skip EAGAIN errors
if (strpos($msg, "errno=11") !== false) {
return;
}
throw new StreamException("Error writing to stream: $msg ($errno)", $errno);
});
try {
// Use conditional, because PHP doesn't like getting null passed
if ($this->chunkSize) {
$written = \fwrite($this->resource, $data, $this->chunkSize);
} else {
$written = \fwrite($this->resource, $data);
}
}
finally {
restore_error_handler();
}
from byte-stream.
What happens if you only delete the feof
and don't bother with the error handler? Does it just keep waiting to write then?
from byte-stream.
There was no error, so it was fine but i guess the proper way should be to handle fwrite errors, shouldn't it?
from byte-stream.
I'm just trying to understand why feof
hangs, but fwrite
succeeds. The custom error handler is probably fine. I think EAGAIN writes are uncommon enough that the performance difference will be negligible.
from byte-stream.
On macOS EAGAIN
seems to equal 35 rather than 11. PHP has some extension specific constants that expose this number (PCNTL_EAGAIN
, SOCKET_EAGAIN
, and MSG_EAGAIN
). Will have to look if there's another way to find this value.
from byte-stream.
Using strpos("Resource temporarily unavailable")
also works for me. Can I depend on that error message though?
Edit: Looks like no, that is also an OS-dependent message.
Removing the feof
check from the initial write in ResourceOutputStream::send()
causes the test testClosedRemoteSocketWithFork
to fail, so I'm not sure we can remove that entirely.
from byte-stream.
Does it fail also with the error handler?
I get temporarily unavailable
on Linux but i first thought errno=11 would be safer. It shouldnt be a big deal to have a platform dependent check, right?
from byte-stream.
Platform dependent checks are always ugly. Error number will be better than message, because these messages can be localized.
from byte-stream.
@brstgt The test still fails with the error handler.
Maybe we should be looking at why feof
is hanging on a non-blocking stream.
from byte-stream.
I encountered hanging feof resulting in StreamException("The stream was closed by the peer").
If it results in a StreamException
, it doesn't hang. Could you clarify what hang means?
from byte-stream.
from byte-stream.
The only thing I recall that might result in hanging are fragmented TLS records (packets), but we have never verified that.
from byte-stream.
Seems like https://github.com/php/php-src/blob/9a497f5c10ee547234b678208875ef3490870bb7/ext/openssl/xp_ssl.c#L2475-L2476 is the problem that results in the hang.
from byte-stream.
See php/php-src#3729 for a fix.
from byte-stream.
The latest PHP releases are fixed now.
from byte-stream.
Related Issues (20)
- Low bandwidth v2.0.0-beta.13, v2.0.0-beta.14 HOT 10
- Consider avoiding stream_socket_shutdown HOT 3
- Error in Amp\ByteStream\splitLines()
- ReadableStream: Clear data from buffer on read HOT 6
- Broken symlink in docs HOT 2
- Immediate reads and writes might result in blocking HOT 2
- Modify chunk size on the fly HOT 5
- ResourceOutputStream interrupts writing without consumer giving information what was written/unwritten HOT 11
- Problem writing to stream HOT 6
- InputStreamChain HOT 3
- ResourceOutputStream treats open stream as closed HOT 5
- Can cause infinite loop in caller code HOT 2
- Invalid watcher issue in ResourceInputStream
- LineReader custom delimiter HOT 2
- Ability to read particular length from stream HOT 4
- Assertion fail: Trying to read from a previously fclose()'d resource (Windows) HOT 3
- Add InputStream::close
- Add CancellationToken to InputStream::read
- The url inside the composer.json should be in their secure version? HOT 2
- ReadableResourceStream::read() length should reattempt a read if less data is returned? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from byte-stream.