|
Posted by VS on 11/26/05 17:08
Stefan Rybacki wrote:
> ross wrote:
>
>> Hi Group,
>> ...
>>
>
>
> I guess a socket connection will help you.
>
> http://de3.php.net/fsockopen
Here's an exmaple I found and use to get the last modified time of a
remote file:
function filemtime_remote($uri)
{
$uri = parse_url($uri);
$uri['port'] = isset($uri['port']) ? $uri['port'] : 80;
// TimeOut
$tout = 5;
$handle = @fsockopen($uri['host'], $uri['port'], $errno, $errstr,
$tout);
if(!$handle)
return 0;
fputs($handle,"HEAD $uri[path] HTTP/1.1\r\nHost: $uri[host]\r\n\r\n");
$result = 0;
while(!feof($handle))
{
$line = fgets($handle,1024);
if(!trim($line))
break;
$col = strpos($line,':');
if($col !== false)
{
$header = trim(substr($line,0,$col));
$value = trim(substr($line,$col+1));
if(strtolower($header) == 'last-modified')
{
$result = strtotime($value);
break;
}
}
}
fclose($handle);
return $result;
}
$URL="http://www.xxxxx.com/filename.txt";
$tsrem = filemtime_remote($URL);
--
VS
Navigation:
[Reply to this message]
|