PHP和Linux上的原始套接字 [英] PHP and RAW SOCKETS on linux
问题描述
是否足够做一个
须藤setcap CAP_NET_RAW = EIP的/ usr / bin中/ PHP5
能在PHP(不CLI)在Linux中使用原始套接字?
如果是的,那么它不工作(但开始在CLI工作,但没有使用Apache)
所以我想我必须给这些权限到Apache为好,但我无法找出如何。
你能帮助我吗?
从PHP脚本错误:警告:socket_create():无法创建插座[1]:操作在
PHP脚本:
$包=\\ X08 \\ X00 \\ x7d \\ X4B \\ X00 \\ X00 \\ X00 \\ x00PingHost
$插座= socket_create(AF_INET,SOCK_RAW,1);
如果($插座!== FALSE){
socket_set_option($插座,SOL_SOCKET,SO_RCVTIMEO,阵列('秒'=> 10,'微秒'= 0));
呼应创建平安插座!'; socket_connect($插座,的gethostbyname('noczone.com'),空);
socket_send($插座,$包,函数strlen($包),0);
如果(socket_read($插座,255)){
$结果= microtime中(真) - $ TS;
}其他{
回声错误code:没有PING';
}
socket_close($插座);
}其他{
呼应'无法创建PING插座!';
}
您是否尝试过:须藤setcap CAP_NET_RAW = $ EIP(其中的httpd)
?
什么是你得到的错误?
Is it enough to do a
sudo setcap cap_net_raw=eip /usr/bin/php5
to be able to use RAW SOCKETS in PHP (not CLI) in Linux ?
If yes, well it is not working (but started to work in CLI but not using Apache)
So I guess I have to give those permissions to Apache as well, but I couldn't find out how.
Can you help me?
errors from the PHP script :
Warning: socket_create(): Unable to create socket [1]: Operation not permitted in
the php script :
$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
$socket = socket_create(AF_INET, SOCK_RAW, 1);
if ($socket !== false) {
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 10, 'usec' => 0));
echo 'Creating PING Socket !';
socket_connect($socket, gethostbyname('noczone.com'), null);
socket_send($socket, $package, strLen($package), 0);
if (socket_read($socket, 255)) {
$result = microtime(true) - $ts;
} else {
echo 'Error Code : No PING';
}
socket_close($socket);
} else {
echo 'Failed Creating PING Socket !';
}
Have you tried:
sudo setcap cap_net_raw=eip $(which httpd)
?
What's the error you're getting?
这篇关于PHP和Linux上的原始套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!