Skip to content

Commit 9f04466

Browse files
authored
Merge pull request #316 from clue-labs/php7.1
Update to require PHP 7.1+
2 parents a2b4fe1 + 3523f51 commit 9f04466

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1377
-1632
lines changed

.github/workflows/ci.yml

-23
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ jobs:
2222
- 7.3
2323
- 7.2
2424
- 7.1
25-
- 7.0
26-
- 5.6
27-
- 5.5
28-
- 5.4
29-
- 5.3
3025
steps:
3126
- uses: actions/checkout@v4
3227
- uses: shivammathur/setup-php@v2
3328
with:
3429
php-version: ${{ matrix.php }}
3530
coverage: xdebug
3631
ini-file: development
37-
- run: composer config secure-http false && composer config repo.packagist composer http://packagist.org && composer config preferred-install source
38-
if: ${{ matrix.php < 5.5 && matrix.os == 'windows-2022' }} # legacy PHP on Windows is allowed to use insecure downloads until it will be removed again
3932
- run: composer install
4033
- run: vendor/bin/phpunit --coverage-text
4134
if: ${{ matrix.php >= 7.3 }}
@@ -54,19 +47,3 @@ jobs:
5447
coverage: xdebug
5548
- run: composer install
5649
- run: vendor/bin/phpunit --coverage-text
57-
58-
PHPUnit-hhvm:
59-
name: PHPUnit (HHVM)
60-
runs-on: ubuntu-22.04
61-
continue-on-error: true
62-
steps:
63-
- uses: actions/checkout@v4
64-
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
65-
- name: Run hhvm composer.phar install
66-
uses: docker://hhvm/hhvm:3.30-lts-latest
67-
with:
68-
args: hhvm composer.phar install
69-
- name: Run hhvm vendor/bin/phpunit
70-
uses: docker://hhvm/hhvm:3.30-lts-latest
71-
with:
72-
args: hhvm vendor/bin/phpunit

README.md

+64-81
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,13 @@ Optionally, you can specify [TCP socket context options](https://www.php.net/man
423423
for the underlying stream socket resource like this:
424424

425425
```php
426-
$socket = new React\Socket\SocketServer('[::1]:8080', array(
427-
'tcp' => array(
426+
$socket = new React\Socket\SocketServer('[::1]:8080', [
427+
'tcp' => [
428428
'backlog' => 200,
429429
'so_reuseport' => true,
430430
'ipv6_v6only' => true
431-
)
432-
));
431+
]
432+
]);
433433
```
434434

435435
> Note that available [socket context options](https://www.php.net/manual/en/context.socket.php),
@@ -447,11 +447,11 @@ which in its most basic form may look something like this if you're using a
447447
PEM encoded certificate file:
448448

449449
```php
450-
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8080', array(
451-
'tls' => array(
450+
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8080', [
451+
'tls' => [
452452
'local_cert' => 'server.pem'
453-
)
454-
));
453+
]
454+
]);
455455
```
456456

457457
> Note that the certificate file will not be loaded on instantiation but when an
@@ -463,25 +463,25 @@ If your private key is encrypted with a passphrase, you have to specify it
463463
like this:
464464

465465
```php
466-
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', array(
467-
'tls' => array(
466+
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', [
467+
'tls' => [
468468
'local_cert' => 'server.pem',
469469
'passphrase' => 'secret'
470-
)
471-
));
470+
]
471+
]);
472472
```
473473

474474
By default, this server supports TLSv1.0+ and excludes support for legacy
475-
SSLv2/SSLv3. As of PHP 5.6+ you can also explicitly choose the TLS version you
475+
SSLv2/SSLv3. You can also explicitly choose the TLS version you
476476
want to negotiate with the remote side:
477477

478478
```php
479-
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', array(
480-
'tls' => array(
479+
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', [
480+
'tls' => [
481481
'local_cert' => 'server.pem',
482482
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
483-
)
484-
));
483+
]
484+
]);
485485
```
486486

487487
> Note that available [TLS context options](https://www.php.net/manual/en/context.ssl.php),
@@ -588,11 +588,11 @@ Optionally, you can specify [socket context options](https://www.php.net/manual/
588588
for the underlying stream socket resource like this:
589589

590590
```php
591-
$server = new React\Socket\TcpServer('[::1]:8080', null, array(
591+
$server = new React\Socket\TcpServer('[::1]:8080', null, [
592592
'backlog' => 200,
593593
'so_reuseport' => true,
594594
'ipv6_v6only' => true
595-
));
595+
]);
596596
```
597597

598598
> Note that available [socket context options](https://www.php.net/manual/en/context.socket.php),
@@ -628,9 +628,9 @@ PEM encoded certificate file:
628628

629629
```php
630630
$server = new React\Socket\TcpServer(8000);
631-
$server = new React\Socket\SecureServer($server, null, array(
631+
$server = new React\Socket\SecureServer($server, null, [
632632
'local_cert' => 'server.pem'
633-
));
633+
]);
634634
```
635635

636636
> Note that the certificate file will not be loaded on instantiation but when an
@@ -643,22 +643,22 @@ like this:
643643

644644
```php
645645
$server = new React\Socket\TcpServer(8000);
646-
$server = new React\Socket\SecureServer($server, null, array(
646+
$server = new React\Socket\SecureServer($server, null, [
647647
'local_cert' => 'server.pem',
648648
'passphrase' => 'secret'
649-
));
649+
]);
650650
```
651651

652652
By default, this server supports TLSv1.0+ and excludes support for legacy
653-
SSLv2/SSLv3. As of PHP 5.6+ you can also explicitly choose the TLS version you
653+
SSLv2/SSLv3. You can also explicitly choose the TLS version you
654654
want to negotiate with the remote side:
655655

656656
```php
657657
$server = new React\Socket\TcpServer(8000);
658-
$server = new React\Socket\SecureServer($server, null, array(
658+
$server = new React\Socket\SecureServer($server, null, [
659659
'local_cert' => 'server.pem',
660660
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
661-
));
661+
]);
662662
```
663663

664664
> Note that available [TLS context options](https://www.php.net/manual/en/context.ssl.php),
@@ -971,9 +971,9 @@ If you want to revert to the old behavior of only doing an IPv4 lookup and
971971
only attempt a single IPv4 connection, you can set up the `Connector` like this:
972972

973973
```php
974-
$connector = new React\Socket\Connector(array(
974+
$connector = new React\Socket\Connector([
975975
'happy_eyeballs' => false
976-
));
976+
]);
977977
```
978978

979979
Similarly, you can also affect the default DNS behavior as follows.
@@ -985,9 +985,9 @@ If you explicitly want to use a custom DNS server (such as a local DNS relay or
985985
a company wide DNS server), you can set up the `Connector` like this:
986986

987987
```php
988-
$connector = new React\Socket\Connector(array(
988+
$connector = new React\Socket\Connector([
989989
'dns' => '127.0.1.1'
990-
));
990+
]);
991991

992992
$connector->connect('localhost:80')->then(function (React\Socket\ConnectionInterface $connection) {
993993
$connection->write('...');
@@ -999,9 +999,9 @@ If you do not want to use a DNS resolver at all and want to connect to IP
999999
addresses only, you can also set up your `Connector` like this:
10001000

10011001
```php
1002-
$connector = new React\Socket\Connector(array(
1002+
$connector = new React\Socket\Connector([
10031003
'dns' => false
1004-
));
1004+
]);
10051005

10061006
$connector->connect('127.0.0.1:80')->then(function (React\Socket\ConnectionInterface $connection) {
10071007
$connection->write('...');
@@ -1016,9 +1016,9 @@ can also set up your `Connector` like this:
10161016
$dnsResolverFactory = new React\Dns\Resolver\Factory();
10171017
$resolver = $dnsResolverFactory->createCached('127.0.1.1');
10181018

1019-
$connector = new React\Socket\Connector(array(
1019+
$connector = new React\Socket\Connector([
10201020
'dns' => $resolver
1021-
));
1021+
]);
10221022

10231023
$connector->connect('localhost:80')->then(function (React\Socket\ConnectionInterface $connection) {
10241024
$connection->write('...');
@@ -1031,18 +1031,18 @@ respects your `default_socket_timeout` ini setting (which defaults to 60s).
10311031
If you want a custom timeout value, you can simply pass this like this:
10321032

10331033
```php
1034-
$connector = new React\Socket\Connector(array(
1034+
$connector = new React\Socket\Connector([
10351035
'timeout' => 10.0
1036-
));
1036+
]);
10371037
```
10381038

10391039
Similarly, if you do not want to apply a timeout at all and let the operating
10401040
system handle this, you can pass a boolean flag like this:
10411041

10421042
```php
1043-
$connector = new React\Socket\Connector(array(
1043+
$connector = new React\Socket\Connector([
10441044
'timeout' => false
1045-
));
1045+
]);
10461046
```
10471047

10481048
By default, the `Connector` supports the `tcp://`, `tls://` and `unix://`
@@ -1051,7 +1051,7 @@ pass boolean flags like this:
10511051

10521052
```php
10531053
// only allow secure TLS connections
1054-
$connector = new React\Socket\Connector(array(
1054+
$connector = new React\Socket\Connector([
10551055
'tcp' => false,
10561056
'tls' => true,
10571057
'unix' => false,
@@ -1070,15 +1070,15 @@ pass arrays of context options like this:
10701070

10711071
```php
10721072
// allow insecure TLS connections
1073-
$connector = new React\Socket\Connector(array(
1074-
'tcp' => array(
1073+
$connector = new React\Socket\Connector([
1074+
'tcp' => [
10751075
'bindto' => '192.168.0.1:0'
1076-
),
1077-
'tls' => array(
1076+
],
1077+
'tls' => [
10781078
'verify_peer' => false,
10791079
'verify_peer_name' => false
1080-
),
1081-
));
1080+
],
1081+
]);
10821082

10831083
$connector->connect('tls://localhost:443')->then(function (React\Socket\ConnectionInterface $connection) {
10841084
$connection->write('...');
@@ -1087,15 +1087,15 @@ $connector->connect('tls://localhost:443')->then(function (React\Socket\Connecti
10871087
```
10881088

10891089
By default, this connector supports TLSv1.0+ and excludes support for legacy
1090-
SSLv2/SSLv3. As of PHP 5.6+ you can also explicitly choose the TLS version you
1090+
SSLv2/SSLv3. You can also explicitly choose the TLS version you
10911091
want to negotiate with the remote side:
10921092

10931093
```php
1094-
$connector = new React\Socket\Connector(array(
1095-
'tls' => array(
1094+
$connector = new React\Socket\Connector([
1095+
'tls' => [
10961096
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
1097-
)
1098-
));
1097+
]
1098+
]);
10991099
```
11001100

11011101
> For more details about context options, please refer to the PHP documentation
@@ -1117,14 +1117,14 @@ $tls = new React\Socket\SecureConnector($tcp);
11171117

11181118
$unix = new React\Socket\UnixConnector();
11191119

1120-
$connector = new React\Socket\Connector(array(
1120+
$connector = new React\Socket\Connector([
11211121
'tcp' => $tcp,
11221122
'tls' => $tls,
11231123
'unix' => $unix,
11241124

11251125
'dns' => false,
11261126
'timeout' => false,
1127-
));
1127+
]);
11281128

11291129
$connector->connect('google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
11301130
$connection->write('...');
@@ -1192,9 +1192,9 @@ You can optionally pass additional
11921192
to the constructor like this:
11931193

11941194
```php
1195-
$tcpConnector = new React\Socket\TcpConnector(null, array(
1195+
$tcpConnector = new React\Socket\TcpConnector(null, [
11961196
'bindto' => '192.168.0.1:0'
1197-
));
1197+
]);
11981198
```
11991199

12001200
Note that this class only allows you to connect to IP-port-combinations.
@@ -1363,20 +1363,20 @@ You can optionally pass additional
13631363
to the constructor like this:
13641364

13651365
```php
1366-
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
1366+
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
13671367
'verify_peer' => false,
13681368
'verify_peer_name' => false
1369-
));
1369+
]);
13701370
```
13711371

13721372
By default, this connector supports TLSv1.0+ and excludes support for legacy
1373-
SSLv2/SSLv3. As of PHP 5.6+ you can also explicitly choose the TLS version you
1373+
SSLv2/SSLv3. You can also explicitly choose the TLS version you
13741374
want to negotiate with the remote side:
13751375

13761376
```php
1377-
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
1377+
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
13781378
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
1379-
));
1379+
]);
13801380
```
13811381

13821382
> Advanced usage: Internally, the `SecureConnector` relies on setting up the
@@ -1490,19 +1490,10 @@ composer require react/socket:^3@dev
14901490
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
14911491

14921492
This project aims to run on any platform and thus does not require any PHP
1493-
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and HHVM.
1494-
It's *highly recommended to use the latest supported PHP version* for this project,
1495-
partly due to its vast performance improvements and partly because legacy PHP
1496-
versions require several workarounds as described below.
1497-
1498-
Secure TLS connections received some major upgrades starting with PHP 5.6, with
1499-
the defaults now being more secure, while older versions required explicit
1500-
context options.
1501-
This library does not take responsibility over these context options, so it's
1502-
up to consumers of this library to take care of setting appropriate context
1503-
options as described above.
1504-
1505-
PHP < 7.3.3 (and PHP < 7.2.15) suffers from a bug where feof() might
1493+
extensions and supports running on PHP 7.1 through current PHP 8+.
1494+
It's *highly recommended to use the latest supported PHP version* for this project.
1495+
1496+
Legacy PHP < 7.3.3 (and PHP < 7.2.15) suffers from a bug where feof() might
15061497
block with 100% CPU usage on fragmented TLS records.
15071498
We try to work around this by always consuming the complete receive
15081499
buffer at once to avoid stale data in TLS buffers. This is known to
@@ -1511,21 +1502,13 @@ cause very large data chunks for high throughput scenarios. The buggy
15111502
behavior can still be triggered due to network I/O buffers or
15121503
malicious peers on affected versions, upgrading is highly recommended.
15131504

1514-
PHP < 7.1.4 (and PHP < 7.0.18) suffers from a bug when writing big
1505+
Legacy PHP < 7.1.4 suffers from a bug when writing big
15151506
chunks of data over TLS streams at once.
15161507
We try to work around this by limiting the write chunk size to 8192
15171508
bytes for older PHP versions only.
15181509
This is only a work-around and has a noticable performance penalty on
15191510
affected versions.
15201511

1521-
This project also supports running on HHVM.
1522-
Note that really old HHVM < 3.8 does not support secure TLS connections, as it
1523-
lacks the required `stream_socket_enable_crypto()` function.
1524-
As such, trying to create a secure TLS connections on affected versions will
1525-
return a rejected promise instead.
1526-
This issue is also covered by our test suite, which will skip related tests
1527-
on affected versions.
1528-
15291512
## Tests
15301513

15311514
To run the test suite, you first need to clone this repo and then install all

0 commit comments

Comments
 (0)