Events.php 846 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * 用于检测业务代码死循环或者长时间阻塞等问题
  4. * 如果发现业务卡死,可以将下面declare打开(去掉//注释),并执行php start.php reload
  5. * 然后观察一段时间workerman.log看是否有process_timeout异常
  6. */
  7. //declare(ticks=1);
  8. use \GatewayWorker\Lib\Gateway;
  9. /**
  10. * 主逻辑
  11. */
  12. class Events
  13. {
  14. // 当有客户端连接时,将client_id返回,让mvc框架判断当前uid并执行绑定
  15. public static function onConnect($client_id)
  16. {
  17. Gateway::sendToClient($client_id, json_encode(array(
  18. 'type' => 'init',
  19. 'client_id' => $client_id
  20. )));
  21. }
  22. // GatewayWorker建议不做任何业务逻辑,onMessage留空即可
  23. public static function onMessage($client_id, $message)
  24. {
  25. }
  26. //当用户断开连接时触发
  27. public static function onClose($client_id)
  28. {
  29. }
  30. }