2008/03/31 21:30

How to put timeout when opening URL by fopen ?


Here's the simplest way to implement that.

<?php
    $timeout = 3;
    $old = ini_set('default_socket_timeout', $timeout);
    $file = fopen('http://example.com', 'r');
    ini_set('default_socket_timeout', $old);
    stream_set_timeout($file, $timeout);
    stream_set_blocking($file, 0);
    //the rest is standard
?>
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.