8000 [HttpClient] Make native stream support non blocking mode by Nek- · Pull Request #35187 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

Nek-
Copy link
Contributor
@Nek- Nek- commented Jan 3, 2020

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:

  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 the initialization of the stream, not after that.
Q A
Branch? 4.4
Bug fix? yes
New feature? yes/no
Deprecations? no
Tickets Fix #34944
License MIT
Doc PR Already documented (doesn't work)

@Nek- Nek- changed the title Add stream_set_option to stream wrapper [HttpClient] Make native stream support non blocking mode Jan 3, 2020
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.
@Nek- Nek- force-pushed the feature/make-stream-non-blocking branch from 6df8186 to 80e4f22 Compare January 3, 2020 10:59
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);
Copy link
Contributor Author

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']);
Copy link
Contributor Author
@Nek- Nek- Jan 3, 2020

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

Copy link
Member

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.

@Nek-
Copy link
Contributor Author
Nek- commented Jan 3, 2020 8000

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
Copy link
Member

Replaced by #35187, thank you @Nek-

nicolas-grekas added a commit that referenced this pull request Jan 4, 2020
… (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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0