start.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. use \Workerman\WebServer;
  3. use \GatewayWorker\Gateway;
  4. use \GatewayWorker\BusinessWorker;
  5. // gateway
  6. $gateway = new Gateway("Websocket://0.0.0.0:8585");
  7. $gateway->name = 'TodpoleGateway';
  8. $gateway->count = 4;
  9. $gateway->lanIp = '127.0.0.1';
  10. $gateway->startPort = 4000;
  11. $gateway->pingInterval = 10;
  12. $gateway->pingData = '{"type":"ping"}';
  13. /*
  14. // 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
  15. $gateway->onConnect = function($connection)
  16. {
  17. $connection->onWebSocketConnect = function($connection , $http_header)
  18. {
  19. // 可以在这里判断连接来源是否合法,不合法就关掉连接
  20. // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
  21. if($_SERVER['HTTP_ORIGIN'] != 'http://kedou.workerman.net')
  22. {
  23. $connection->close();
  24. }
  25. // onWebSocketConnect 里面$_GET $_SERVER是可用的
  26. // var_dump($_GET, $_SERVER);
  27. };
  28. };
  29. */
  30. // bussinessWorker
  31. $worker = new BusinessWorker();
  32. $worker->name = 'TodpoleBusinessWorker';
  33. $worker->count = 4;
  34. // WebServer
  35. $web = new WebServer("http://0.0.0.0:8686");
  36. $web->count = 2;
  37. $web->addRoot('www.your_domain.com', __DIR__.'/Web');