0
如果需要在php函数中使用备份服务器,使用file_get_contents会有什么好方法。file_get_contents如果失败,请使用其他服务器
我可以想到这样的事情,不知道它是否会按预期工作。
<?php
$data = file_get_contents("http:/server1.com"); // Lets say this is down (timeout or other error)
if(!$data){
$data = file_get_contents("http://server1backup.com");
}
//do something with data
?>
也许以某种方式与尝试块?从来没有用过他们...
我也想设置file_get_contents超时时间较短的时间,如5秒,所以它不会在1服务器上等待太久,如果它的下降。