1--TEST-- 2Test socket_sendto with MSG_ZEROCOPY 3--EXTENSIONS-- 4sockets 5--SKIPIF-- 6<?php 7$arch = php_uname('m'); 8if (!defined("SO_ZEROCOPY")) { 9 die('skip SO_ZEROCOPY'); 10} 11if (strpos($arch, 'ppc') !== false || strpos($arch, 'powerpc') !== false) { 12 die('skip not for powerpc arch'); 13} 14if (getenv('CIRRUS_CI') && strpos($arch, 'aarch64') !== false) { 15 die('xfail Broken on Cirrus + arm'); 16} 17?> 18--FILE-- 19<?php 20$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 21if (!$socket) { 22 die('Unable to create AF_UNIX socket'); 23} 24$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); 25if (!$s) { 26 die('Unable to create AF_UNIX socket'); 27} 28if (!socket_set_option($socket, SOL_SOCKET, SO_ZEROCOPY, 1)) { 29 die("Unable to set the socket option to SO_ZEROCOPY"); 30} 31if (!socket_set_nonblock($s)) { 32 die('Unable to set nonblocking mode for socket'); 33} 34$address = '127.0.0.1'; 35$port = 3001; 36if (!socket_bind($s, $address, $port)) { 37 die("Unable to bind to $address"); 38} 39 40$msg = str_repeat("0123456789abcdef", 1024); 41$len = strlen($msg); 42$bytes_recv = 0; 43$bytes_sent = socket_sendto($socket, $msg, $len, MSG_ZEROCOPY, $address, $port); 44if (socket_recvfrom($s, $resp, 0, MSG_ERRQUEUE, $address, $port) == -1) die ("recvfrom MSG_ERRQUEUE"); 45$bytes_recv = socket_recvfrom($s, $resp, 16, 0, $address, $port); 46echo "$bytes_sent sent!\n"; 47echo "$bytes_recv received!\n"; 48echo "Received $resp!"; 49socket_close($s); 50socket_close($socket); 51?> 52--EXPECTF-- 5316384 sent! 5416 received! 55Received 0123456789abcdef! 56