|  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
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at richardneill dot org
New email:
PHP Version: OS:


 [2010-06-13 02:28 UTC] php at richardneill dot org
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

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-13 02:38 UTC]
-Status: Open +Status: Wont fix
 [2010-06-13 02:38 UTC]
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]
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 14:01:30 2024 UTC