fb_pixel

filemtime - external file

Development | Web Development
Description
Hi I have function, but it's slow

function filemtime_remote($uri)
{
$uri = parse_url($uri);
$handle = @fsockopen($uri['host'],80);
if(!$handle)
return 0;

fputs($handle,"GET $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;
}
Attachments
No attachments
Info
Description
this one is faster, but it's still not it.
$fileis = 'https://skuska.sk/productimg/'.$nazfoto.'.jpg';
$modiftpd = get_headers($fileis, 3);
$modiftp = strtotime($modiftpd['Last-Modified']);
echo $modiftp;

on January 10th, 2020 (5:10 pm)
Description
Here's an example 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;
}

on January 10th, 2020 (8:14 pm)
Description
I have 6939 files for control and script runtime 13.4384914994 min. It's been a long time. Hosting gives me after 10 min timeout. Crazy is, that with function filemtime ('road') is 3.4213 min
on January 11th, 2020 (7:40 pm)
All coments
This job has not been commented yet.