Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Created January 28, 2015 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/df5eed3a56447ec67713 to your computer and use it in GitHub Desktop.
Save codearachnid/df5eed3a56447ec67713 to your computer and use it in GitHub Desktop.
Simple PHP ping request
<?php
function ping($host){
if(exec('echo EXEC') == 'EXEC'){
exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval);
} elseif( function_exists('fsocketopen') ){
$port = 80;
$timeout= 6;
$fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
if ( ! $fsock ){
$rval = 0;
} else {
$rval = 1;
}
}
return $rval === 0;
}
/* check if the host is up $host can also be an ip address */
$host = 'www.google.com';
$up = ping($host);
@hossein-rp
Copy link

hossein-rp commented Nov 5, 2023

how can i use it to test a vpn in php?

@codearachnid
Copy link
Author

don't be a spammer

@hossein-rp
Copy link

no realy i have a question .

look at first check this page.

here is a lot of v2ray configs and i want to get their pings to use them in v2rayng vpn

may main Q is how to get v2ray configs pings?
your function doesnt work on them

and thank you

ه

@hossein-rp
Copy link

actually i want to send them to a telegram channel with their ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment