note 79605 modified in function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 19:23:21 +0000 |
| Subject: | note 79605 modified in function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142292@lists.php.net to get a copy of this message | ||
Make a ping test with PHP
The problem with fsockopen is you have to known the destination port.
A real ping function could be :
<?php
function php_ping($url) {
$addr=parse_url($url);
$host=$addr['host'];
exec("ping -c 1 -w 1 $host", $list);
if (strpos($list[4],"1 received")>0) {
return true ;
}
return false;
}
?>
But if your router refuse the ping ... the result will be always false > you may test both
(fsockopen and ping)
--was--
Make a ping test with PHP
The problem with fsockopen is you have to known the destination port.
A real ping function could be :
function php_ping($url) {
$addr=parse_url($url);
$host=$addr['host'];
exec("ping -c 1 -w 1 $host", $list);
if (strpos($list[4],"1 received")>0) {
return true ;
}
return false;
}
But if your router refuse the ping ... the result will be always false > you may test both
(fsockopen and ping)
http://php.net/manual/en/function.fsockopen.php