Benchmark.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Benchmark
  4. * 方法1:ab -n 100000 -c200 127.0.0.1:56789/
  5. * 方法2:使用workerman自带的benchmark软件,只支持64位linux系统
  6. * ①:./benchmark -n10000 -h1 -c400 -p56789 127.0.0.1 // 命令含义是400并发线程,连接127.0.0.1:56789端口发送一个hello\n扥带服务端返回一个hello\n后断开连接,这样运行10000次
  7. * ②:./benchmark -n1 -h10000 -c1000 -p56789 127.0.0.1 // 命令含义是1000并发线程,连接127.0.0.1:56789端口连续发送10000个hello\n
  8. * @author walkor <workerman.net>
  9. */
  10. class Benchmark extends Man\Core\SocketWorker
  11. {
  12. /**
  13. * @see Worker::dealInput()
  14. */
  15. public function dealInput($buffer)
  16. {
  17. // 由于请求包都小于一个MTU,不会有分包,这里直接返回0
  18. return 0;
  19. }
  20. /**
  21. * 处理业务
  22. * @see Worker::dealProcess()
  23. */
  24. public function dealProcess($buffer)
  25. {
  26. // 是HTTP协议
  27. if('G' == $buffer[0] )
  28. {
  29. $this->sendToClient("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhello");
  30. return $this->closeClient($this->currentDealFd);
  31. }
  32. // 是benchmark脚本
  33. return $this->sendToClient($buffer);
  34. }
  35. }