내가 자꾸 까먹어서 쓰는 개발 이야기/PHP
원격지 파일 체크하기
FIL.
2012. 7. 3. 11:35
728x90
function shutdown_connection()
{
global $fp;
socket_shutdown($fp);
fclose($fp);
}
function check_file($url, $timeout = 10)
{
$url_stuff = parse_url($url);
$host_name = $url_stuff[host];
$fp = fsockopen($host_name, 80, $errno, $errstr, 2);
if (!$fp) {
return 0;
} else {
socket_set_timeout($fp, $timeout);
if (fputs($fp, "GET $url HTTP/1.0\n")) {
$res = fread($fp, 1024);
if (stristr($res, "Content-Type: image")) {
return 1;
}
}
fclose($fp);
}
return 0;
}