unixloop.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Streams Based Unix Domain Loopback test
  3. --SKIPIF--
  4. <?php
  5. if (array_search("unix",stream_get_transports()) === false)
  6. die('SKIP No support for UNIX domain sockets.');
  7. ?>
  8. --FILE--
  9. <?php
  10. $uniqid = uniqid();
  11. if (file_exists("/tmp/$uniqid.sock"))
  12. die('Temporary socket already exists.');
  13. /* Setup socket server */
  14. $server = stream_socket_server("unix:///tmp/$uniqid.sock");
  15. if (!$server) {
  16. die('Unable to create AF_UNIX socket [server]');
  17. }
  18. /* Connect to it */
  19. $client = stream_socket_client("unix:///tmp/$uniqid.sock");
  20. if (!$client) {
  21. die('Unable to create AF_UNIX socket [client]');
  22. }
  23. /* Accept that connection */
  24. $socket = stream_socket_accept($server);
  25. if (!$socket) {
  26. die('Unable to accept connection');
  27. }
  28. fwrite($client, "ABCdef123\n");
  29. $data = fread($socket, 10);
  30. var_dump($data);
  31. fclose($client);
  32. fclose($socket);
  33. fclose($server);
  34. unlink("/tmp/$uniqid.sock");
  35. ?>
  36. --EXPECT--
  37. string(10) "ABCdef123
  38. "