ConnectionInterface.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Workerman\Connection;
  3. use Workerman\Events\Libevent;
  4. use Workerman\Events\Select;
  5. use Workerman\Events\EventInterface;
  6. use Workerman\Worker;
  7. use \Exception;
  8. /**
  9. * connection
  10. * @author walkor<walkor@workerman.net>
  11. */
  12. abstract class ConnectionInterface
  13. {
  14. /**
  15. * statistics for status
  16. * @var array
  17. */
  18. public static $statistics = array(
  19. 'total_request' => 0,
  20. 'throw_exception' => 0,
  21. 'send_fail' => 0,
  22. );
  23. /**
  24. * when receive data, onMessage will be run
  25. * @var callback
  26. */
  27. public $onMessage = null;
  28. /**
  29. * when connection close, onClose will be run
  30. * @var callback
  31. */
  32. public $onClose = null;
  33. /**
  34. * when something wrong ,onError will be run
  35. * @var callback
  36. */
  37. public $onError = null;
  38. /**
  39. * send buffer to client
  40. * @param string $send_buffer
  41. * @return void|boolean
  42. */
  43. abstract public function send($send_buffer);
  44. /**
  45. * get remote ip
  46. * @return string
  47. */
  48. abstract public function getRemoteIp();
  49. /**
  50. * get remote port
  51. */
  52. abstract public function getRemotePort();
  53. /**
  54. * close the connection
  55. * @void
  56. */
  57. abstract public function close($data = null);
  58. }