1. Go to this page and download the library: Download rxnet/socket 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/ */
rxnet / socket example snippets
$connector = new \Rxnet\Socket\Connector($loop);
$options = [
// See http://php.net/manual/en/context.socket.php for all tcp options
'tcp'=> [
'backlog' => 200,
'so_reuseport' => true,
'ipv6_v6only' => true
],
// see http://php.net/manual/en/context.ssl.php for all ssl options
'tls' => [
'verify_peer' => false
]
];
$connector->connect('www.google.fr:80', $options)
->timeout(100)
->subscribe(
function (\Rxnet\Socket\Connection $connection) use ($loop) {
$connection
->subscribe(
function ($data) {
// Every chunk received will give onNext
var_dump($data);
},
function (\Exception $e) {
echo $e->getMessage();
},
function () {
echo 'completed';
}
);
$connection->write("GET /?gfe_rd=cr&dcr=0&ei=YWhsWsTDIZOm8wep_beACA HTTP/1.0\r\nHost: www.google.fr\r\n\r\n");
}
);