-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] Make native stream support non blocking mode #35187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit is based on the job of @mcsky symfony#34969 With this change it allows using a stream in a select_streams function. (which is basics in non-blocking streams in PHP) It adds specific errors in case the user tries to change the timeout or the write buffer because: 1. The stream is read only (so it makes no sense to update the write buffer) 2. By design, we need to specify the timeout at initialization of the stream, not after that.
6df8186
to
80e4f22
Compare
case STREAM_OPTION_BLOCKING: | ||
return stream_set_blocking($this->handle, $arg1); | ||
case STREAM_OPTION_READ_TIMEOUT: | ||
trigger_error(sprintf('Modifying the timeout after starting the stream is not supported by the StreamWrapper.'), E_USER_WARNING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP will trigger fatal error because we return false. But I think more precision is a good thing.
$this->assertTrue(stream_set_blocking($stream, 0)); | ||
|
||
// Help wanted. I've no idea why this test does not pass. | ||
// $this->assertFalse(stream_get_meta_data($stream)['blocked']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've no idea where data from stream_get_meta_data
comes.
It looks like default values are always returned while using a streamwrapper ?!
https://github.com/php/php-src/blob/9099dbd9614b37b48818ac24e2020b0d756b7e1e/ext/standard/streamsfuncs.c#L511-L515
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, we cannot define these when using stream wrappers.
After testing, it looks like this is not enough to make it non-blocking (it's not related to the comment I wrote in the code). And that's because of the usage of a generator in the StreamWrapper. @nicolas-grekas would you be ok to add another implementation so it can actually be non-blocking? |
… (nicolas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] fix support for non-blocking resource streams | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35187, Fix #35187 | License | MIT | Doc PR | - Commits ------- c651f63 [HttpClient] fix support for non-blocking resource streams
This commit is based on the job of @mcsky #34969
With this change, it allows using a stream in a select_streams function. (which is basics in non-blocking streams in PHP)
It adds specific errors in case the user tries to change the timeout or the write buffer because: