WebsocketClient.php 730 B

123456789101112131415161718192021222324
  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::$logFile = sprintf('%s/test-websocket-client.log', sys_get_temp_dir());
  17. Worker::$command = 'start';
  18. Worker::runAll();