PHP code example of wyrihaximus / react-opportunistic-tls
1. Go to this page and download the library: Download wyrihaximus/react-opportunistic-tls library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wyrihaximus / react-opportunistic-tls example snippets
use WyriHaximus\React\Socket;
use function React\Promise\Stream\first;
$connector = new Socket\Connector();
$connector->connect('opportunistic+tls://example.com:5432/')->then(function (Socket\OpportunisticTlsConnectionInterface $startTlsConnection) {
$connection->write('let\'s encrypt?');
return first($connection)->then(function ($data) use ($connection) {
if ($data === 'yes') {
return $connection->enableEncryption();
}
return $stream;
});
})->then(function (Socket\ConnectionInterface $connection) {
$connection->write('Hello!');
});
use WyriHaximus\React\Socket;
$socket = new Socket\SocketServer('opportunistic+tls://127.0.0.1:8000', array(
'tls' => array(
'local_cert' => 'server.pem',
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
)
));
$server->on('connection', static function (Socket\OpportunisticTlsConnectionInterface $connection) use ($server) {
return $connection->enableEncryption();
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.