Date from HTTP headers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc

    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
  • Andy Hassall

    #2
    Re: Date from HTTP headers

    On Sat, 27 Mar 2004 01:31:40 -0000, Marc <marc@svn.net > wrote:
    [color=blue]
    >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.[/color]

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

    Output:

    array(10) {
    ["wrapper_da ta"]=>
    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=ut f-8"
    }
    ["wrapper_ty pe"]=>
    string(4) "HTTP"
    ["stream_typ e"]=>
    string(10) "tcp_socket "
    ["mode"]=>
    string(2) "r+"
    ["unread_byt es"]=>
    int(4140)
    ["seekable"]=>
    bool(false)
    ["uri"]=>
    string(17) "http://localhost/"
    ["timed_out"]=>
    bool(false)
    ["blocked"]=>
    bool(true)
    ["eof"]=>
    bool(false)
    }

    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

    Comment

    Working...