stream.php 455 B

123456789101112131415161718192021
  1. <?php
  2. $fp = stream_socket_client("tcp://127.0.0.1:9502", $errno, $errstr, 30);
  3. if (!$fp) {
  4. exit("$errstr ($errno)<br />\n");
  5. }
  6. fwrite($fp, "HELLO world");
  7. function stream_onRead($fp)
  8. {
  9. echo fread($fp, 1024)."\n";
  10. sleep(1);
  11. swoole_event_write($fp, "hello world");
  12. //swoole_event_set($fp, null, null, SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE);
  13. //swoole_event_del($fp);
  14. //fclose($fp);
  15. }
  16. swoole_event_add($fp, 'stream_onRead');
  17. echo "start\n";