async_client.php 637 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. $client = new swoole_client(SWOOLE_SOCK_UNIX_STREAM, SWOOLE_SOCK_ASYNC);
  3. $client->on("connect", function (swoole_client $cli)
  4. {
  5. $cli->send("GET / HTTP/1.1\r\n\r\n");
  6. });
  7. $client->on("receive", function (swoole_client $cli, $data)
  8. {
  9. echo "Receive: $data";
  10. $cli->send(str_repeat('A', 100) . "\n");
  11. });
  12. $client->on("error", function (swoole_client $cli)
  13. {
  14. echo "error: [" . $cli->errCode . "] " . socket_strerror($cli->errCode) . "\n";
  15. });
  16. $client->on("close", function (swoole_client $cli)
  17. {
  18. echo "Connection close\n";
  19. });
  20. $client->connect(__DIR__ . '/svr.sock', 0, -1);
  21. swoole_event_wait();
  22. echo "exit\n";