File modification time on PHP<5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
papieros
Forum Newbie
Posts: 8
Joined: Wed Jan 19, 2005 12:15 pm

File modification time on PHP<5

Post by papieros »

Hello,

I can't find a way to check remote file modification time in PHP4.
cause filemtime (stat,fstat) works on local files only, and there is
no get_headers function. I appraciate any ideas, thx.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Remote file modification time? There are functions in PHP4 to do this using FTP if that's any help?

ftp_mdtm()
papieros
Forum Newbie
Posts: 8
Joined: Wed Jan 19, 2005 12:15 pm

Post by papieros »

Thanks, i will look at this function but i rather need a way to get modification time via HTTP protocol.
'remote file' - I meant : 'server-side' file.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

On another server? Not localhost? I don't think http can do that... that's more of an ftp thing.
papieros
Forum Newbie
Posts: 8
Joined: Wed Jan 19, 2005 12:15 pm

Post by papieros »

Why?, the simplest way to get 'modification-time' via http is
to get http header and examine 'Last-Modified' field.
My question could be:'how to get this header in PHP4'
(in PHP5 get_headers works fine).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Last-Modified is an optional header response.

Fsockopen and curl are often used to request a remote page to fetch the headers returned.
papieros
Forum Newbie
Posts: 8
Joined: Wed Jan 19, 2005 12:15 pm

Post by papieros »

Last-Modified is an optional header response.
That's OK. the problem is: i want to minimize the transfer by checking
if the file was modified before the download, if there is no information
i can download it and check localy (most of the files i deal with has the
info )
Fsockopen and curl are often used to request a remote page to fetch the headers returned.
Is there no more simple way to check the header in php?, i can't believe,
but thanks anyway. (curl could be useful for other things i do)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there are no other ways to check the headers in a response outside of shelling out to a command line tool..
papieros
Forum Newbie
Posts: 8
Joined: Wed Jan 19, 2005 12:15 pm

Post by papieros »

Hm, I wonder why? checking response header seems to be
easy to perform and important action, what's the reason for that,
anybody knows?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

important, maybe.. often needed, not so much. It probably wasn't really requested until 5 was under development and 4 was probably under feature lock by that point.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Wanted to know regarding Last-Modified time of a http page.
Any way to figure out the remote file modification time in PHP 4 or PHP 5 ?

Server doesnt return Last-Modified always. If Last-Modified isnt returned, can we assume Date to be the Last-Modified ?

Thanks
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Does this help?

Code: Select all

echo date('F d Y H:i:s', filemtime(__FILE__));
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Code: Select all

$url = 'http://devnetwork.net';
$LastModified = getLastModifiedTime($url);
echo  $LastModified;
A get_headers($url, 1) works but many servers dont return Last-Modified time. I was wondering if theres an alternative.
Post Reply