@@ -423,13 +423,13 @@ Optionally, you can specify [TCP socket context options](https://www.php.net/man
423
423
for the underlying stream socket resource like this:
424
424
425
425
``` php
426
- $socket = new React\Socket\SocketServer('[::1]:8080', array(
427
- 'tcp' => array(
426
+ $socket = new React\Socket\SocketServer('[::1]:8080', [
427
+ 'tcp' => [
428
428
'backlog' => 200,
429
429
'so_reuseport' => true,
430
430
'ipv6_v6only' => true
431
- )
432
- ) );
431
+ ]
432
+ ] );
433
433
```
434
434
435
435
> 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
447
447
PEM encoded certificate file:
448
448
449
449
``` 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' => [
452
452
'local_cert' => 'server.pem'
453
- )
454
- ) );
453
+ ]
454
+ ] );
455
455
```
456
456
457
457
> 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
463
463
like this:
464
464
465
465
``` 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' => [
468
468
'local_cert' => 'server.pem',
469
469
'passphrase' => 'secret'
470
- )
471
- ) );
470
+ ]
471
+ ] );
472
472
```
473
473
474
474
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
476
476
want to negotiate with the remote side:
477
477
478
478
``` 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' => [
481
481
'local_cert' => 'server.pem',
482
482
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
483
- )
484
- ) );
483
+ ]
484
+ ] );
485
485
```
486
486
487
487
> 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/
588
588
for the underlying stream socket resource like this:
589
589
590
590
``` php
591
- $server = new React\Socket\TcpServer('[::1]:8080', null, array(
591
+ $server = new React\Socket\TcpServer('[::1]:8080', null, [
592
592
'backlog' => 200,
593
593
'so_reuseport' => true,
594
594
'ipv6_v6only' => true
595
- ) );
595
+ ] );
596
596
```
597
597
598
598
> Note that available [ socket context options] ( https://www.php.net/manual/en/context.socket.php ) ,
@@ -628,9 +628,9 @@ PEM encoded certificate file:
628
628
629
629
``` php
630
630
$server = new React\Socket\TcpServer(8000);
631
- $server = new React\Socket\SecureServer($server, null, array(
631
+ $server = new React\Socket\SecureServer($server, null, [
632
632
'local_cert' => 'server.pem'
633
- ) );
633
+ ] );
634
634
```
635
635
636
636
> Note that the certificate file will not be loaded on instantiation but when an
@@ -643,22 +643,22 @@ like this:
643
643
644
644
``` php
645
645
$server = new React\Socket\TcpServer(8000);
646
- $server = new React\Socket\SecureServer($server, null, array(
646
+ $server = new React\Socket\SecureServer($server, null, [
647
647
'local_cert' => 'server.pem',
648
648
'passphrase' => 'secret'
649
- ) );
649
+ ] );
650
650
```
651
651
652
652
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
654
654
want to negotiate with the remote side:
655
655
656
656
``` php
657
657
$server = new React\Socket\TcpServer(8000);
658
- $server = new React\Socket\SecureServer($server, null, array(
658
+ $server = new React\Socket\SecureServer($server, null, [
659
659
'local_cert' => 'server.pem',
660
660
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
661
- ) );
661
+ ] );
662
662
```
663
663
664
664
> 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
971
971
only attempt a single IPv4 connection, you can set up the ` Connector ` like this:
972
972
973
973
``` php
974
- $connector = new React\Socket\Connector(array(
974
+ $connector = new React\Socket\Connector([
975
975
'happy_eyeballs' => false
976
- ) );
976
+ ] );
977
977
```
978
978
979
979
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
985
985
a company wide DNS server), you can set up the ` Connector ` like this:
986
986
987
987
``` php
988
- $connector = new React\Socket\Connector(array(
988
+ $connector = new React\Socket\Connector([
989
989
'dns' => '127.0.1.1'
990
- ) );
990
+ ] );
991
991
992
992
$connector->connect('localhost:80')->then(function (React\Socket\ConnectionInterface $connection) {
993
993
$connection->write('...');
@@ -999,9 +999,9 @@ If you do not want to use a DNS resolver at all and want to connect to IP
999
999
addresses only, you can also set up your ` Connector ` like this:
1000
1000
1001
1001
``` php
1002
- $connector = new React\Socket\Connector(array(
1002
+ $connector = new React\Socket\Connector([
1003
1003
'dns' => false
1004
- ) );
1004
+ ] );
1005
1005
1006
1006
$connector->connect('127.0.0.1:80')->then(function (React\Socket\ConnectionInterface $connection) {
1007
1007
$connection->write('...');
@@ -1016,9 +1016,9 @@ can also set up your `Connector` like this:
1016
1016
$dnsResolverFactory = new React\Dns\Resolver\Factory();
1017
1017
$resolver = $dnsResolverFactory->createCached('127.0.1.1');
1018
1018
1019
- $connector = new React\Socket\Connector(array(
1019
+ $connector = new React\Socket\Connector([
1020
1020
'dns' => $resolver
1021
- ) );
1021
+ ] );
1022
1022
1023
1023
$connector->connect('localhost:80')->then(function (React\Socket\ConnectionInterface $connection) {
1024
1024
$connection->write('...');
@@ -1031,18 +1031,18 @@ respects your `default_socket_timeout` ini setting (which defaults to 60s).
1031
1031
If you want a custom timeout value, you can simply pass this like this:
1032
1032
1033
1033
``` php
1034
- $connector = new React\Socket\Connector(array(
1034
+ $connector = new React\Socket\Connector([
1035
1035
'timeout' => 10.0
1036
- ) );
1036
+ ] );
1037
1037
```
1038
1038
1039
1039
Similarly, if you do not want to apply a timeout at all and let the operating
1040
1040
system handle this, you can pass a boolean flag like this:
1041
1041
1042
1042
``` php
1043
- $connector = new React\Socket\Connector(array(
1043
+ $connector = new React\Socket\Connector([
1044
1044
'timeout' => false
1045
- ) );
1045
+ ] );
1046
1046
```
1047
1047
1048
1048
By default, the ` Connector ` supports the ` tcp:// ` , ` tls:// ` and ` unix:// `
@@ -1051,7 +1051,7 @@ pass boolean flags like this:
1051
1051
1052
1052
``` php
1053
1053
// only allow secure TLS connections
1054
- $connector = new React\Socket\Connector(array(
1054
+ $connector = new React\Socket\Connector([
1055
1055
'tcp' => false,
1056
1056
'tls' => true,
1057
1057
'unix' => false,
@@ -1070,15 +1070,15 @@ pass arrays of context options like this:
1070
1070
1071
1071
``` php
1072
1072
// allow insecure TLS connections
1073
- $connector = new React\Socket\Connector(array(
1074
- 'tcp' => array(
1073
+ $connector = new React\Socket\Connector([
1074
+ 'tcp' => [
1075
1075
'bindto' => '192.168.0.1:0'
1076
- ) ,
1077
- 'tls' => array(
1076
+ ] ,
1077
+ 'tls' => [
1078
1078
'verify_peer' => false,
1079
1079
'verify_peer_name' => false
1080
- ) ,
1081
- ) );
1080
+ ] ,
1081
+ ] );
1082
1082
1083
1083
$connector->connect('tls://localhost:443')->then(function (React\Socket\ConnectionInterface $connection) {
1084
1084
$connection->write('...');
@@ -1087,15 +1087,15 @@ $connector->connect('tls://localhost:443')->then(function (React\Socket\Connecti
1087
1087
```
1088
1088
1089
1089
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
1091
1091
want to negotiate with the remote side:
1092
1092
1093
1093
``` php
1094
- $connector = new React\Socket\Connector(array(
1095
- 'tls' => array(
1094
+ $connector = new React\Socket\Connector([
1095
+ 'tls' => [
1096
1096
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
1097
- )
1098
- ) );
1097
+ ]
1098
+ ] );
1099
1099
```
1100
1100
1101
1101
> For more details about context options, please refer to the PHP documentation
@@ -1117,14 +1117,14 @@ $tls = new React\Socket\SecureConnector($tcp);
1117
1117
1118
1118
$unix = new React\Socket\UnixConnector();
1119
1119
1120
- $connector = new React\Socket\Connector(array(
1120
+ $connector = new React\Socket\Connector([
1121
1121
'tcp' => $tcp,
1122
1122
'tls' => $tls,
1123
1123
'unix' => $unix,
1124
1124
1125
1125
'dns' => false,
1126
1126
'timeout' => false,
1127
- ) );
1127
+ ] );
1128
1128
1129
1129
$connector->connect('google.com:80')->then(function (React\Socket\ConnectionInterface $connection) {
1130
1130
$connection->write('...');
@@ -1192,9 +1192,9 @@ You can optionally pass additional
1192
1192
to the constructor like this:
1193
1193
1194
1194
``` php
1195
- $tcpConnector = new React\Socket\TcpConnector(null, array(
1195
+ $tcpConnector = new React\Socket\TcpConnector(null, [
1196
1196
'bindto' => '192.168.0.1:0'
1197
- ) );
1197
+ ] );
1198
1198
```
1199
1199
1200
1200
Note that this class only allows you to connect to IP-port-combinations.
@@ -1363,20 +1363,20 @@ You can optionally pass additional
1363
1363
to the constructor like this:
1364
1364
1365
1365
``` php
1366
- $secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
1366
+ $secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
1367
1367
'verify_peer' => false,
1368
1368
'verify_peer_name' => false
1369
- ) );
1369
+ ] );
1370
1370
```
1371
1371
1372
1372
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
1374
1374
want to negotiate with the remote side:
1375
1375
1376
1376
``` php
1377
- $secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
1377
+ $secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
1378
1378
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
1379
- ) );
1379
+ ] );
1380
1380
```
1381
1381
1382
1382
> Advanced usage: Internally, the ` SecureConnector ` relies on setting up the
@@ -1490,19 +1490,10 @@ composer require react/socket:^3@dev
1490
1490
See also the [ CHANGELOG] ( CHANGELOG.md ) for details about version upgrades.
1491
1491
1492
1492
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
1506
1497
block with 100% CPU usage on fragmented TLS records.
1507
1498
We try to work around this by always consuming the complete receive
1508
1499
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
1511
1502
behavior can still be triggered due to network I/O buffers or
1512
1503
malicious peers on affected versions, upgrading is highly recommended.
1513
1504
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
1515
1506
chunks of data over TLS streams at once.
1516
1507
We try to work around this by limiting the write chunk size to 8192
1517
1508
bytes for older PHP versions only.
1518
1509
This is only a work-around and has a noticable performance penalty on
1519
1510
affected versions.
1520
1511
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
-
1529
1512
## Tests
1530
1513
1531
1514
To run the test suite, you first need to clone this repo and then install all
0 commit comments