PHP code example of ekstazi / websocket-stream-client-amphp
1. Go to this page and download the library: Download ekstazi/websocket-stream-client-amphp 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/ */
ekstazi / websocket-stream-client-amphp example snippets
use Amp\Websocket\Options;
use \ekstazi\websocket\client\amphp\ConnectorFactory;
use \ekstazi\websocket\client\ConnectionFactory;
// ....
return [
ConnectionFactory::class => new ConnectorFactory(),
// this is optional config for default options to connections
"config" => [
"websocket" => [
'clientOptions' => Options::createClientDefault(),
]
]
];
use \Psr\Container\ContainerInterface;
use \ekstazi\websocket\client\ConnectionFactory;
use \Psr\Http\Message\RequestInterface;
use \ekstazi\websocket\client\Connection;
/** @var ContainerInterface $container */
/** @var ConnectionFactory $connector */
/** @var RequestInterface $request */
$connector = $container->get(ConnectionFactory::class);
/** @var Connection $stream */
$stream = yield $connector->connect($request, Connection::MODE_BINARY);
use \Psr\Http\Message\RequestInterface;
use \ekstazi\websocket\client\Connection;
use function \ekstazi\websocket\client\connect;
/** @var RequestInterface $request */
/** @var Connection $stream */
$stream = yield connect($request, Connection::MODE_BINARY);
use \ekstazi\websocket\client\ConnectionFactory;
use \Psr\Http\Message\RequestInterface;
use \ekstazi\websocket\client\Connection;
use function \ekstazi\websocket\client\connector;
/** @var RequestInterface $request */
/** @var ConnectionFactory $connector */
$connector = connector();
/** @var Connection $stream */
$stream = yield $connector->connect($request, Connection::MODE_BINARY);
use Amp\Websocket\Options;
use \ekstazi\websocket\client\ConnectionFactory;
use \Psr\Http\Message\RequestInterface;
use \ekstazi\websocket\client\Connection;
use function \ekstazi\websocket\client\connector;
/** @var RequestInterface $request */
/** @var ConnectionFactory $connector */
$connector = connector();
/** @var Connection $stream */
$stream = yield $connector->connect($request, Connection::MODE_BINARY, Options::createClientDefault()->withoutHeartbeat());
use Amp\Websocket\Options;
use ekstazi\websocket\client\amphp\Connector;
use \ekstazi\websocket\client\ConnectionFactory;
use \Psr\Http\Message\RequestInterface;
use \ekstazi\websocket\client\Connection;
/** @var RequestInterface $request */
/** @var ConnectionFactory $connector */
$connector = new Connector(null, Options::createClientDefault());
/** @var Connection $stream */
$stream = yield $connector->connect($request, Connection::MODE_BINARY);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.