I’m including a local class that requests a file from a remote server. This process is rather unreliable — because the remote server is often overloaded — and I sometimes have to wait 20 or so seconds before the include gives up and continues.
I would like to have a limit on the execution time of the included script; say, five seconds.
Current code:
include('siteclass.class.php');
Update:
My code inside the class:
$movie = str_replace(" ","+",$movie);
$string = join('',file($siteurl.$l.'/moviename-'.$movie));
if(!$i) { static $i = 1;}
if($file_array = $string)
{
$result = Return_Substrings($file_array, '<item>', '</item>');
foreach($result as $res) {
That’s basically it, as far as the loading goes. The internal processing takes about 0.1 s. I guess that’s pretty doable.
Note that I didn’t test this code, take this like a proposition :
$fp = fopen('siteclass.class.php', 'r'); stream_set_timeout($fp, 2); stream_set_timeout($fp,$timeout); $info = stream_get_meta_data($fp); if ($info['timed_out']) { echo "Connection Timed Out!"; } else { $file = ''; while (!feof($fp)) { $file .= fgets($fp); } eval($file); }The timeout is set in seconds, so the example set it to two seconds.