I have lots of websites, where i use a lot of includes on. Those files I include are on an external include-server. My problem is: I want to make those files redundant, so if the include server goes down, they are taken from my second include server. Doing that manually on each website will take by far too long, so I wonder if there is a way to do it for instance on the server-side (so if the server is down it forwards to the other server).
Here is an example of how I usually include my files:
<?php
$url = 'http://myincludeserver.com/folder/fileiwanttoinclude.php';
function get_data($url)
{
$ch = curl_init($url);
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_REQUEST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data($url);
if(!empty($returned_content))
{
echo $returned_content;
}
else
{
include('includes/local_error_message.php');
};
?>
Thanks for reading!
$.ajax({ //... success: function(data, textStatus, xhr) { console.log(xhr.status); }, complete: function(xhr, textStatus) { console.log(xhr.status); } });this then you know server is failed or notget_datafunction has been duplicated 1000+ times?