test_buffer.php 816 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. $client = new swoole_client(SWOOLE_SOCK_TCP); //同步阻塞
  3. if(empty($argv[1]))
  4. {
  5. $loop = 1;
  6. }
  7. else
  8. {
  9. $loop = intval($argv[1]);
  10. }
  11. $_s = microtime(true);
  12. if(!$client->connect('127.0.0.1', 9501))
  13. {
  14. exit("connect fail\n");
  15. }
  16. for($i=0; $i<$loop; $i++)
  17. {
  18. $client->send(str_repeat("A", 8000).$i."[0]");
  19. //$client->send(str_repeat("A", 20).$i."[1]");
  20. //$client->send(str_repeat("A", 30).$i."[2]");
  21. //$ret = $client->send("GET / HTTP/1.1\r\n");
  22. //$client->send("Host: localhost\r\n");
  23. //$client->send("Connection: keep-alive\r\n");
  24. $client->send("\r\n\r\n");
  25. //$data = $client->recv(1024, 0);
  26. //if($data === false)
  27. //{
  28. // echo "#{$i} recv fail.break\n";
  29. // break;
  30. // }
  31. //echo "recv[$i]",$data,"\n";
  32. }
  33. sleep(1000);
  34. echo "$i: ",$data,"\n";
  35. echo "test ok. use".((microtime(true) - $_s)*1000)."ms\n";