Edit report at http://bugs.php.net/bug.php?id=52071&edit=1

 ID:               52071
 Updated by:       ras...@php.net
 Reported by:      php at richardneill dot org
 Summary:          RFE: ping
 Status:           Wont fix
 Type:             Feature/Change Request
 Package:          Network related
 Operating System: Linux
 PHP Version:      Irrelevant

 New Comment:

But the reason the exec() works is because you are starting a new
setuid-root 

process to do it.  There is no way to do it from a non-root process,
which means 

you can't eliminate the exec(), which means a PHP implementation would
internally 

have to do exec('ping') which makes no sense.


Previous Comments:
------------------------------------------------------------------------
[2010-06-13 03:13:07] php at richardneill dot org

I do see your point. On the other hand, I can (as a normal user) quite
easily use ping by relying on that Setuid binary, via exec(). Wouldn't
this approach work? 



(the key win here is to eliminate needing exec(), which tends to upset
nervous managers during code-review)

------------------------------------------------------------------------
[2010-06-13 02:38:27] ras...@php.net

This is not going to work in most PHP environments because doing
raw-socket ICMP 

requests, like ping does requires root access.  You will notice that
your ping 

binary is setuid-root on your machine, so unless you are running PHP as
root, 

doing it from within PHP simply won't work.



If you do have root access, it isn't that hard to do with a 

socket_create(AF_INET, SOCK_RAW,  getprotobyname('icmp')) call, but
since it 

wouldn't work for most people, I don't see the point in adding it to
PHP.

------------------------------------------------------------------------
[2010-06-13 02:28:38] php at richardneill dot org

Description:
------------
Surprisingly, PHP is missing the ability to ping another host (and check
it's 

alive). So I'd like to make a request to add it. I'd suggest using
something 

like fping rather than standard ping, as this is more script-friendly -
for 

example, fping can be made to return immediately as soon as it discovers
that 

a given host is alive. For example:

 fping -q -B1 www.php.net



I know that there is Net_Ping available via PEAR, but often PEAR
extensions 

aren't available on many hosting environments; likewise it's awkward to


package a PHP web-application when the PEAR extension isn't already
packaged 

for the distro. Is ping suficiently fundamental to be considered core?

Test script:
---------------
This command should either exist in 2 forms, or have several options.
Typical use cases are:



1. Is machine X alive (and responding to Pings)

2. Can I do a DNS lookup + route to that machine

3. What is the packet loss fraction.



This is easy enough to do by using exec(), but it would be nice to have
a native function. Thanks.



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52071&edit=1

Reply via email to