1--TEST--
2Streams 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
14    /* Setup socket server */
15    $server = stream_socket_server("unix:///tmp/$uniqid.sock");
16    if (!$server) {
17        die('Unable to create AF_UNIX socket [server]');
18    }
19
20    /* Connect to it */
21    $client = stream_socket_client("unix:///tmp/$uniqid.sock");
22    if (!$client) {
23        die('Unable to create AF_UNIX socket [client]');
24    }
25
26    /* Accept that connection */
27    $socket = stream_socket_accept($server);
28    if (!$socket) {
29        die('Unable to accept connection');
30    }
31
32    fwrite($client, "ABCdef123\n");
33
34    $data = fread($socket, 10);
35    var_dump($data);
36
37    fclose($client);
38    fclose($socket);
39    fclose($server);
40    unlink("/tmp/$uniqid.sock");
41?>
42--EXPECT--
43string(10) "ABCdef123
44"
45