Disambiguation: 'connection' doesn't mean database connection.
Scenario 1: I am taking weather feed from a 3rd party site, and it's working fine. Suddenly my client complained that it's broken, and showing an error. Then quickly I just simply commented out the codes.
Scenario 2: Suppose I embedded Google fonts into my website and it's looking fine. Suddenly Google's services are banned in a country, and my site looks dumb.
If I can put a checker like:
<?php
// suppose this is the URL of my connection I need to connect my site on loading
$connection = http://www.feed-from-somewhere.com/feed/my-feed123
if ( isset( $connection ) ) {
// show the feed from 3rd party site
} else {
// do my backup plan for the feed instead
}
?>
But I can't find any way. If I can do such thing than it would be better for all such 3rd party sharing and site won't malfunction in future.
Waiting for a nice solution...
Maybe you can try the fopen() function in php. as described in the php.net fopen() --
"If filename is of the form "scheme://...", it is assumed to be a URL and PHP will search for a protocol handler (also known as a wrapper) for that scheme."...
example could be:
@$connection = fopen("http://iewuhf.com/", "r");
//note @ is used to suppress the error ortherwise, if connection fails, a warning
//will be displayed
if(!$connection){
echo 'false';
}else{
echo 'true';
}