worker_server.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | Workerman设置 仅对 php think worker:server 指令有效
  13. // +----------------------------------------------------------------------
  14. return [
  15. // 扩展自身需要的配置
  16. 'protocol' => 'websocket', // 协议 支持 tcp udp unix http websocket text
  17. 'host' => '0.0.0.0', // 监听地址
  18. 'port' => 2345, // 监听端口
  19. 'socket' => '', // 完整监听地址
  20. 'context' => [], // socket 上下文选项
  21. // 'worker_class' => '', // 自定义Workerman服务类名 支持数组定义多个服务
  22. 'worker_class' =>[
  23. \app\worker\controller\Worker::class
  24. ], // 自定义Workerman服务类名 支持数组定义多个服务
  25. // 支持workerman的所有配置参数
  26. 'name' => 'thinkphp',
  27. 'count' => 4,
  28. 'daemonize' => false,
  29. 'pidFile' => '',
  30. // 支持事件回调
  31. // onWorkerStart
  32. 'onWorkerStart' => function ($worker) {
  33. },
  34. // onWorkerReload
  35. 'onWorkerReload' => function ($worker) {
  36. },
  37. // onConnect
  38. 'onConnect' => function ($connection) {
  39. },
  40. // onMessage
  41. 'onMessage' => function ($connection, $data) {
  42. // $connection->send('receive success');
  43. },
  44. // onClose
  45. 'onClose' => function ($connection) {
  46. },
  47. // onError
  48. 'onError' => function ($connection, $code, $msg) {
  49. echo "error [ $code ] $msg\n";
  50. },
  51. ];