Skip to content
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

Async HTTP Client PHP 7.0 fixes: Non-blocking mode after SSL handshake, recomputing the stream key #80

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

adamziel
Copy link
Collaborator

Closes #79

Makes the AsyncHTTPClient usable in PHP 7.0 with two changes:

In PHP <= 7.1 and later, making the socket non-blocking before the SSL handshake makes the stream_socket_enable_crypto() call always return false. Therefore, we only make the socket non-blocking after the SSL handshake.

In PHP <= 7.1, stream_select doesn't preserve the keys of the array:

stream_select( $read, $write, $except, 0, $timeout_microseconds );
// If $read is array( 1=> $fp ) before the stream_select() call,
// it will be array( 0 => $fp ) after.
foreach ( $read as $k => $stream ) {
	$chunks[ $k ] = fread( $stream, $length );
}

Therefore, we recompute the key using array_search() on these older PHP versions.

…e, recomputing the stream key

Makes the AsyncHTTPClient usable in PHP 7.0 with two changes:

In PHP <= 7.1 and later, making the socket non-blocking before the
SSL handshake makes the stream_socket_enable_crypto() call always return
false. Therefore, we only make the socket non-blocking after the
SSL handshake.

In PHP <= 7.1, stream_select doesn't preserve the keys of the array:

```php
stream_select( $read, $write, $except, 0, $timeout_microseconds );
// If $read is array( 1=> $fp ) before the stream_select() call,
// it will be array( 0 => $fp ) after.
foreach ( $read as $k => $stream ) {
	$chunks[ $k ] = fread( $stream, $length );
}
```

Therefore, we recompute the key using array_search() on these older
PHP versions.
@adamziel adamziel added bug Something isn't working V1 blocker HTTP Client labels Mar 19, 2024
@adamziel adamziel merged commit d3f2556 into trunk Mar 19, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker bug Something isn't working HTTP Client V1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async HTTP Client runs into an infinite loop on PHP 7.0 and 7.1
1 participant