Beispiel #1
1
<?php

include __DIR__ . "/mcast_helpers.php.inc";
$path = __DIR__ . "/unix_sock";
@unlink($path);
echo "creating send socket\n";
$sends1 = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err");
var_dump($sends1);
socket_set_nonblock($sends1) or die("Could not put in non-blocking mode");
echo "creating receive socket\n";
$s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err");
var_dump($s);
$br = socket_bind($s, $path) or die("err");
var_dump($br);
socket_set_nonblock($s) or die("Could not put in non-blocking mode");
$r = socket_sendmsg($sends1, ["name" => ["path" => $path], "iov" => ["test ", "thing", "\n"], "control" => [["level" => SOL_SOCKET, "type" => SCM_RIGHTS, "data" => [$sends1, STDIN, STDOUT, STDERR]]]], 0);
var_dump($r);
checktimeout($s, 500);
$data = ["name" => [], "buffer_size" => 2000, "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, 3)];
var_dump($data);
if (!socket_recvmsg($s, $data, 0)) {
    die("recvmsg");
}
print_r($data);
error_reporting(0);
$path = __DIR__ . "/unix_sock";
@unlink($path);
Beispiel #2
0
<?php

include __DIR__ . "/mcast_helpers.php.inc";
$path = "/foo_bar";
echo "creating server socket\n";
$servers = socket_create(AF_UNIX, SOCK_STREAM, 0) or die("err");
socket_bind($servers, $path) or die("Could not bind");
socket_listen($servers) or die("Could not listen");
socket_set_nonblock($servers) or die("Could not put in non-blocking mode");
echo "creating client socket\n";
$clients = socket_create(AF_UNIX, SOCK_STREAM, 0) or die("err");
socket_connect($clients, $path) or die("Error connecting");
$conns = socket_accept($servers) or die("Could not accept connection");
$r = socket_sendmsg($clients, ["iov" => ["test ", "thing", "\n"]], 0);
var_dump($r);
checktimeout($conns, 500);
if (!socket_recv($conns, $buf, 20, 0)) {
    die("recv");
}
print_r($buf);