Skip to content

Update to require PHP 7.1+ #316

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

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update PHP language syntax and remove legacy workarounds
  • Loading branch information
clue committed May 31, 2024
commit c8c9d42bbe46c7f677a445bfcbfff0a1580ccdca
110 changes: 55 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ Optionally, you can specify [TCP socket context options](https://www.php.net/man
for the underlying stream socket resource like this:

```php
$socket = new React\Socket\SocketServer('[::1]:8080', array(
'tcp' => array(
$socket = new React\Socket\SocketServer('[::1]:8080', [
'tcp' => [
'backlog' => 200,
'so_reuseport' => true,
'ipv6_v6only' => true
)
));
]
]);
```

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

```php
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8080', array(
'tls' => array(
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8080', [
'tls' => [
'local_cert' => 'server.pem'
)
));
]
]);
```

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

```php
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', array(
'tls' => array(
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', [
'tls' => [
'local_cert' => 'server.pem',
'passphrase' => 'secret'
)
));
]
]);
```

By default, this server supports TLSv1.0+ and excludes support for legacy
SSLv2/SSLv3. You can also explicitly choose the TLS version you
want to negotiate with the remote side:

```php
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', array(
'tls' => array(
$socket = new React\Socket\SocketServer('tls://127.0.0.1:8000', [
'tls' => [
'local_cert' => 'server.pem',
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
)
));
]
]);
```

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

```php
$server = new React\Socket\TcpServer('[::1]:8080', null, array(
$server = new React\Socket\TcpServer('[::1]:8080', null, [
'backlog' => 200,
'so_reuseport' => true,
'ipv6_v6only' => true
));
]);
```

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

```php
$server = new React\Socket\TcpServer(8000);
$server = new React\Socket\SecureServer($server, null, array(
$server = new React\Socket\SecureServer($server, null, [
'local_cert' => 'server.pem'
));
]);
```

> Note that the certificate file will not be loaded on instantiation but when an
Expand All @@ -643,10 +643,10 @@ like this:

```php
$server = new React\Socket\TcpServer(8000);
$server = new React\Socket\SecureServer($server, null, array(
$server = new React\Socket\SecureServer($server, null, [
'local_cert' => 'server.pem',
'passphrase' => 'secret'
));
]);
```

By default, this server supports TLSv1.0+ and excludes support for legacy
Expand All @@ -655,10 +655,10 @@ want to negotiate with the remote side:

```php
$server = new React\Socket\TcpServer(8000);
$server = new React\Socket\SecureServer($server, null, array(
$server = new React\Socket\SecureServer($server, null, [
'local_cert' => 'server.pem',
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
));
]);
```

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

```php
$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'happy_eyeballs' => false
));
]);
```

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

```php
$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'dns' => '127.0.1.1'
));
]);

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

```php
$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'dns' => false
));
]);

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

$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'dns' => $resolver
));
]);

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

```php
$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'timeout' => 10.0
));
]);
```

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

```php
$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'timeout' => false
));
]);
```

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

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

```php
// allow insecure TLS connections
$connector = new React\Socket\Connector(array(
'tcp' => array(
$connector = new React\Socket\Connector([
'tcp' => [
'bindto' => '192.168.0.1:0'
),
'tls' => array(
],
'tls' => [
'verify_peer' => false,
'verify_peer_name' => false
),
));
],
]);

$connector->connect('tls://localhost:443')->then(function (React\Socket\ConnectionInterface $connection) {
$connection->write('...');
Expand All @@ -1091,11 +1091,11 @@ SSLv2/SSLv3. You can also explicitly choose the TLS version you
want to negotiate with the remote side:

```php
$connector = new React\Socket\Connector(array(
'tls' => array(
$connector = new React\Socket\Connector([
'tls' => [
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
)
));
]
]);
```

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

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

$connector = new React\Socket\Connector(array(
$connector = new React\Socket\Connector([
'tcp' => $tcp,
'tls' => $tls,
'unix' => $unix,

'dns' => false,
'timeout' => false,
));
]);

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

```php
$tcpConnector = new React\Socket\TcpConnector(null, array(
$tcpConnector = new React\Socket\TcpConnector(null, [
'bindto' => '192.168.0.1:0'
));
]);
```

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

```php
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
'verify_peer' => false,
'verify_peer_name' => false
));
]);
```

By default, this connector supports TLSv1.0+ and excludes support for legacy
SSLv2/SSLv3. You can also explicitly choose the TLS version you
want to negotiate with the remote side:

```php
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, array(
$secureConnector = new React\Socket\SecureConnector($dnsConnector, null, [
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
));
]);
```

> Advanced usage: Internally, the `SecureConnector` relies on setting up the
Expand Down
10 changes: 5 additions & 5 deletions examples/01-echo-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

require __DIR__ . '/../vendor/autoload.php';

$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '127.0.0.1:0', array(
'tls' => array(
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
)
));
$socket = new React\Socket\SocketServer($argv[1] ?? '127.0.0.1:0', [
'tls' => [
'local_cert' => $argv[2] ?? __DIR__ . '/localhost.pem'
]
]);

$socket->on('connection', function (React\Socket\ConnectionInterface $connection) {
echo '[' . $connection->getRemoteAddress() . ' connected]' . PHP_EOL;
Expand Down
10 changes: 5 additions & 5 deletions examples/02-chat-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

require __DIR__ . '/../vendor/autoload.php';

$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '127.0.0.1:0', array(
'tls' => array(
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
)
));
$socket = new React\Socket\SocketServer($argv[1] ?? '127.0.0.1:0', [
'tls' => [
'local_cert' => $argv[2] ?? __DIR__ . '/localhost.pem'
]
]);

$socket = new React\Socket\LimitingServer($socket, null);

Expand Down
12 changes: 6 additions & 6 deletions examples/03-http-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@

require __DIR__ . '/../vendor/autoload.php';

$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '127.0.0.1:0', array(
'tls' => array(
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
)
));
$socket = new React\Socket\SocketServer($argv[1] ?? '127.0.0.1:0', [
'tls' => [
'local_cert' => $argv[2] ?? __DIR__ . '/localhost.pem'
]
]);

$socket->on('connection', function (React\Socket\ConnectionInterface $connection) {
echo '[' . $connection->getRemoteAddress() . ' connected]' . PHP_EOL;
Expand All @@ -61,4 +61,4 @@
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});

echo 'Listening on ' . strtr($socket->getAddress(), array('tcp:' => 'http:', 'tls:' => 'https:')) . PHP_EOL;
echo 'Listening on ' . strtr($socket->getAddress(), ['tcp:' => 'http:', 'tls:' => 'https:']) . PHP_EOL;
2 changes: 1 addition & 1 deletion examples/11-http-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use React\Socket\Connector;
use React\Socket\ConnectionInterface;

$host = isset($argv[1]) ? $argv[1] : 'www.google.com';
$host = $argv[1] ?? 'www.google.com';

require __DIR__ . '/../vendor/autoload.php';

Expand Down
2 changes: 1 addition & 1 deletion examples/12-https-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use React\Socket\Connector;
use React\Socket\ConnectionInterface;

$host = isset($argv[1]) ? $argv[1] : 'www.google.com';
$host = $argv[1] ?? 'www.google.com';

require __DIR__ . '/../vendor/autoload.php';

Expand Down
4 changes: 2 additions & 2 deletions examples/22-http-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

require __DIR__ . '/../vendor/autoload.php';

$uri = isset($argv[1]) ? $argv[1] : 'www.google.com';
$uri = $argv[1] ?? 'www.google.com';

if (strpos($uri, '://') === false) {
$uri = 'http://' . $uri;
Expand All @@ -42,7 +42,7 @@
$host .= ':' . $parts['port'];
}
$target = ($parts['scheme'] === 'https' ? 'tls' : 'tcp') . '://' . $parts['host'] . ':' . $parts['port'];
$resource = isset($parts['path']) ? $parts['path'] : '/';
$resource = $parts['path'] ?? '/';
if (isset($parts['query'])) {
$resource .= '?' . $parts['query'];
}
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy