User Contributed Notes 4 notes

Below is a function I wrote to pull the "Last-Modified" header from a given URL. In PHP version 4.3 and above, it takes advantage of the stream_get_meta_data function, and in older version it uses a conventional GET procedure. On failure to connect to $url, it returns NULL. If the server does not return the Last-Modified header, it returns the current time. All times are returned in PHP's integer format (seconds since epoch).

In PHP 5.4.24 and 5.4.25, this command does not correctly return the stream blocking status. It always returns ['blocked'] == 1 regardless of the actual blocking mode. A call to stream_set_blocking($stream, 0) will succeed (return TRUE) and subsequent calls to stream_get_contents($stream) will NOT block, even though a call to stream_get_meta_data($stream) will return 'blocked' == 1. Hopefully this will save some people a bunch of debugging time.

// View the status of that same pipe.// Note that 'blocked' is 1! This appears to be wrong.print_r(stream_get_meta_data($pipes[1]));

// Try to read something. This will block if in blocking mode.// If it does not block, stream_set_blocking() worked but// stream_get_meta_data() is lying about blocking mode.$data = stream_get_contents($pipes[1]);