WebsocketClient.php 650 B

1234567891011121314151617181920212223
  1. <?php
  2. declare(strict_types=1);
  3. use Workerman\Connection\AsyncTcpConnection;
  4. use Workerman\Worker;
  5. require_once __DIR__ . '/vendor/autoload.php';
  6. if (!defined('STDIN')) define('STDIN', fopen('php://stdin', 'r'));
  7. if (!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'w'));
  8. if (!defined('STDERR')) define('STDERR', fopen('php://stderr', 'w'));
  9. $worker = new Worker();
  10. $worker->onWorkerStart = function($worker) {
  11. $con = new AsyncTcpConnection('ws://127.0.0.1:8081');
  12. //%action%
  13. $con->connect();
  14. };
  15. Worker::$pidFile = sprintf('%s/test-websocket-client.pid', sys_get_temp_dir());
  16. Worker::$command = 'start';
  17. Worker::runAll();