I try to use socket_create ICMP to ping Ip read data or not,In Windows10 works,but CentOS7 not working, The error message is "socket_create(): Unable to create socket [1]: Operation not permitted", And I also check phpinfo() enable sockets in CentOS7, Is this problem about root permissions? How can I fix it...
I try to use chmod -R 4777 /var/www/html/MyWeb but still not working
/* ICMP ping packet with a pre-calculated checksum */
$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
$icmp = getprotobyname("icmp");
$socket = socket_create(AF_INET, SOCK_RAW, $icmp);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0));
if (@socket_set_option($socket, SOL_SOCKET, SO_BINDTODEVICE, $iface) === false) return false;
socket_connect($socket, $host, 100);
$ts = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (@socket_read($socket, 255)) {
$result = $host;
} else {
$result = false;
}
socket_close($socket);
The error message is:
socket_create(): Unable to create socket [1]: Operation not permitted