ConnectionInterface.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. 'connection_count'=>0,
  20. 'total_request' => 0,
  21. 'throw_exception' => 0,
  22. 'send_fail' => 0,
  23. );
  24. /**
  25. * when receive data, onMessage will be run
  26. * @var callback
  27. */
  28. public $onMessage = null;
  29. /**
  30. * when connection close, onClose will be run
  31. * @var callback
  32. */
  33. public $onClose = null;
  34. /**
  35. * when something wrong ,onError will be run
  36. * @var callback
  37. */
  38. public $onError = null;
  39. /**
  40. * send buffer to client
  41. * @param string $send_buffer
  42. * @return void|boolean
  43. */
  44. abstract public function send($send_buffer);
  45. /**
  46. * get remote ip
  47. * @return string
  48. */
  49. abstract public function getRemoteIp();
  50. /**
  51. * get remote port
  52. */
  53. abstract public function getRemotePort();
  54. /**
  55. * close the connection
  56. * @void
  57. */
  58. abstract public function close($data = null);
  59. }