顯示具有 resource 標籤的文章。 顯示所有文章
顯示具有 resource 標籤的文章。 顯示所有文章

2014年7月3日 星期四

[Linux] 使用 wget 測試 Remote Resource Availability @ Ubuntu 14.04

wget 有 --spider 模式,挺方便的 :P

$ wget --spider http://www.google.com/favicon.ico
Spider mode enabled. Check if remote file exists.
Resolving www.google.com (www.google.com)... 173.194.33.148, 173.194.33.144, 173.194.33.145, ...
Connecting to www.google.com (www.google.com)|173.194.33.148|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [image/x-icon]
Remote file exists.

2014年6月27日 星期五

[PHP] 使用 CURL 測試 Remote Resource Availability @ Ubuntu 14.04

有些程式跑在對岸,就該測測網路是否可取得啦

<?php
function checkRemoteResourceAvailability($target_url) {
        $ch = curl_init($target_url);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        $status = curl_exec($ch) !== false && curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200;
        curl_close($ch);
        return $status;
}

echo checkRemoteResourceAvailability('http://tw.yahoo.com/favicon.ico') ? "ok" : "not available";