1--TEST-- 2recvmsg(): receive SCM_CREDENTIALS messages 3--SKIPIF-- 4<?php 5if (!extension_loaded('sockets')) { 6die('skip sockets extension not available.'); 7} 8if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { 9die('skip not for Microsoft Windows'); 10} 11--CLEAN-- 12<?php 13$path = __DIR__ . "/unix_sock"; 14@unlink($path); 15 16--FILE-- 17<?php 18include __DIR__."/mcast_helpers.php.inc"; 19$path = __DIR__ . "/unix_sock"; 20 21@unlink($path); 22 23echo "creating send socket\n"; 24$sends1 = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); 25var_dump($sends1); 26socket_set_nonblock($sends1) or die("Could not put in non-blocking mode"); 27 28echo "creating receive socket\n"; 29$s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); 30var_dump($s); 31$br = socket_bind($s, $path) or die("err"); 32var_dump($br); 33socket_set_nonblock($sends1) or die("Could not put in non-blocking mode"); 34socket_set_option($s, SOL_SOCKET, SO_PASSCRED, 1) or die("could not set SO_PASSCRED"); 35 36 37//$r = socket_sendmsg($sends1, [ 38// "iov" => ["test ", "thing", "\n"], 39//], 0); 40$r = socket_sendto($sends1, $msg = "dread", strlen($msg), 0, $path); 41var_dump($r); 42checktimeout($s, 500); 43 44$data = [ 45 "name" => [], 46 "buffer_size" => 2000, 47 "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_CREDENTIALS) 48]; 49if (!socket_recvmsg($s, $data, 0)) die("recvmsg"); 50print_r($data); 51 52$pid = getmypid(); 53var_dump($data['control'][0]['data']['pid'] === $pid); 54 55--EXPECTF-- 56creating send socket 57resource(%d) of type (Socket) 58creating receive socket 59resource(%d) of type (Socket) 60bool(true) 61int(5) 62Array 63( 64 [name] => 65 [control] => Array 66 ( 67 [0] => Array 68 ( 69 [level] => %d 70 [type] => %d 71 [data] => Array 72 ( 73 [pid] => %d 74 [uid] => %d 75 [gid] => %d 76 ) 77 78 ) 79 80 ) 81 82 [iov] => Array 83 ( 84 [0] => dread 85 ) 86 87 [flags] => 0 88) 89bool(true) 90