2
使用我的wordpress functions.php文件來檢查顯示的每個圖像是否已啓動並正在運行或已關閉。我認爲我想要做的就是將這個功能代碼(下面)分解爲兩個。快速查找網站是關閉還是關閉?
函數1:檢查mirror1.com是否啓動(而不是檢查循環中的每個圖像)。根據mirror1.com的http狀態插入if/then語句。 (如果mirror1.com是向下,然後使用mirror2.com) - 傳遞到$ mirror_website
功能2:簡單地傳遞在$ mirror_website ..(前端具有<img src="<?php echo $mirror_website; ?>/image.png">
)
下面的代碼有效,但它檢查每個簡單的圖像,並減慢網站速度。
function amazons3acctreplaceto() {
$url = 'http://www.mirror1.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode) {
$as3replaceto = "www.mirror1.com"; // All's well
} else {
$as3replaceto = "www.mirror2.com"; // not so much
}
由於某種原因,上面的代碼不吐出$ as3replaceto; – 1xxooxx
只有安裝並啓用了apc,它才能正常工作? – Wivlaro