1 <?php
defined('SYSPATH') OR die('No direct access allowed.');
3 * Remote url/file helper.
5 * $Id: remote.php 3917 2009-01-21 03:06:22Z zombor $
9 * @copyright (c) 2007-2008 Kohana Team
10 * @license http://kohanaphp.com/license.html
14 public static function status($url)
16 if ( ! valid
::url($url, 'http'))
19 // Get the hostname and path
20 $url = parse_url($url);
22 if (empty($url['path']))
24 // Request the root document
28 // Open a remote connection
29 $remote = fsockopen($url['host'], 80, $errno, $errstr, 5);
31 if ( ! is_resource($remote))
38 fwrite($remote, 'HEAD '.$url['path'].' HTTP/1.0'.$CRLF);
39 fwrite($remote, 'Host: '.$url['host'].$CRLF);
40 fwrite($remote, 'Connection: close'.$CRLF);
41 fwrite($remote, 'User-Agent: Kohana Framework (+http://kohanaphp.com/)'.$CRLF);
43 // Send one more CRLF to terminate the headers
44 fwrite($remote, $CRLF);
46 while ( ! feof($remote))
49 $line = trim(fgets($remote, 512));
51 if ($line !== '' AND preg_match('#^HTTP/1\.[01] (\d{3})#', $line, $matches))
53 // Response code found
54 $response = (int) $matches[1];
60 // Close the connection
63 return isset($response) ?
$response : FALSE;