I just needed to see if a remote web server was alive, so it didn't really matter to me whether I used ping or a curl command like this.
Here's a modified version of the original source code:
=200 && $httpcode<300){
echo 'worked';
} else {
echo "didn't work";
}
?>
You can find the original source code at this "Lost in Code" URL.
Issue a ping command from a PHP script
As a final option, if you can run the ping command from your command line, you can also just execute it with a PHP ping script, like this:
In my case this didn't work because I wasn't given access to the ping command, but if you do have access to the ping command at the command line, this "PHP exec" example shows how this can work.
REF: https://alvinalexander.com/php/php-ping-scripts-examples-ping-command/
{{tag>php ping}}