I just tested set_time_limit() but apparently readfile('http...'); doesn't honor this setting. The script was executed longer than the amount of time set via set_time_limit, but then aborted before the next "in-script" statment was executed.
But since php 5.2.1 the http url wrapper has a context option timeout
which seems to do the trick.
mysql_close();
$ctx = stream_context_create( array(
'http' => array(
'timeout' => 4.7 // in seconds
)
);
readfile('http://somedomain.com/banner.jpg', false, $ctx);
exit;