471,320 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,320 software developers and data experts.

Date from HTTP headers

I've got a PHP script that's using fopen to connect to a remote web
server and pick up data.

I've run into a problem in calculating elapsed time. The remote web
server outputs a time and I'd like to calculate the difference between
that time and the current time. The problem is that the time on the
remote server isn't in sync with the time on my server (off by about 5
minutes) and this throws off the elapsed time calculations. I know
that the server's date/time are included in the HTTP headers, ex:
Date: Sat, 27 Mar 2004 01:25:25 GMT

So, I'm wondering if there's an easy way to grab that date from the
remote server so that the calculations are more accurate.

Thanks in advance.

-M
Jul 17 '05 #1
1 1875
On Sat, 27 Mar 2004 01:31:40 -0000, Marc <ma**@svn.net> wrote:
I've got a PHP script that's using fopen to connect to a remote web
server and pick up data.

I've run into a problem in calculating elapsed time. The remote web
server outputs a time and I'd like to calculate the difference between
that time and the current time. The problem is that the time on the
remote server isn't in sync with the time on my server (off by about 5
minutes) and this throws off the elapsed time calculations. I know
that the server's date/time are included in the HTTP headers, ex:
Date: Sat, 27 Mar 2004 01:25:25 GMT

So, I'm wondering if there's an easy way to grab that date from the
remote server so that the calculations are more accurate.


<pre>
<?php
$fp = fopen('http://localhost/', 'r');
var_dump(stream_get_meta_data($fp));
?>
</pre>

Output:

array(10) {
["wrapper_data"]=>
array(6) {
[0]=>
string(15) "HTTP/1.1 200 OK"
[1]=>
string(35) "Date: Sat, 27 Mar 2004 01:39:57 GMT"
[2]=>
string(42) "Server: Apache/2.0.49 (Win32) PHP/5.0.0RC1"
[3]=>
string(20) "Content-Length: 7172"
[4]=>
string(17) "Connection: close"
[5]=>
string(37) "Content-Type: text/html;charset=utf-8"
}
["wrapper_type"]=>
string(4) "HTTP"
["stream_type"]=>
string(10) "tcp_socket"
["mode"]=>
string(2) "r+"
["unread_bytes"]=>
int(4140)
["seekable"]=>
bool(false)
["uri"]=>
string(17) "http://localhost/"
["timed_out"]=>
bool(false)
["blocked"]=>
bool(true)
["eof"]=>
bool(false)
}

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by praba kar | last post: by
13 posts views Thread by Dr John Stockton | last post: by
6 posts views Thread by Mike Koerner | last post: by
7 posts views Thread by Ramon | last post: by
2 posts views Thread by Stefan Antonelli | last post: by
1 post views Thread by Akhenaten | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.