php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52071 RFE: ping
Submitted: 2010-06-13 02:28 UTC Modified: 2010-06-13 03:30 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: php at richardneill dot org Assigned:
Status: Wont fix Package: Network related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-06-13 02:28 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-13 02:38 UTC] rasmus@php.net
-Status: Open +Status: Wont fix
 [2010-06-13 02:38 UTC] rasmus@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 03:13 UTC] 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 03:15 UTC] rasmus@php.net
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.
 [2010-06-13 03:30 UTC] php at richardneill dot org
Agreed: php would have to internally exec('ping'). That's not especially pretty, but it's no uglier than having to explicitly do it. The advantage is that the code (and all error cases) have to be handled only once within PHP, rather than by ten thousand different end-users :-)
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri May 14 13:01:24 2021 UTC