Following is the code that will do a remote scrape of 
http://www3.brinkster.com/soa/val/profile/display.asp (which sometimes goes down), 
however, it should time out and produce an error after 5 seconds; instead, sometimes, 
the entire page (http://valsignalandet.com) which includes this script below, takes up 
to 90 seconds to load because of the ASP script locking, in spite of my safeguards.  
Can anyone please help; I'm out of ideas.

Thanx

Phil

<?
  require_once('/users/ppowell/web/php_global_vars.php');

  // OPEN SOCKET CONNECTION TO BRINKSTER SET TO TIMEOUT IN 2 SECONDS
  $res = '';
  $fp = fsockopen('www3.brinkster.com', 80, &$errno, &$errstr, 2) or die('Oops');
  if (!$fp) {
   echo "${font}Cannot profiles at this time. <a 
href=http://www3.brinkster.com/soa/val/profile/view.asp>Click here</a> or try again 
later</font><p>";
  } else {
   $httpStr = "POST /soa/val/profile/display.asp?showLeftNavBanner=1 
HTTP/1.0\r\nAccept: text/*\r\nUser-agent: NC_GET_URL\r\nHost: 
www3.brinkster.com:80\r\n\r\n";
   fputs($fp, $httpStr);
   $start = time();
   
   // DOUBLE TIME SETTING: SET FOR BOTH STREAM TIMEOUT AND FOR DATA LOOPING TIMEOUT TO 
   // ENSURE THAT THE WHOLE PROCESS IS 5 SECONDS OR IT QUITS
   
   // STREAM COMMANDS DON'T WORK ON VAL BECAUSE PHP VERSION IS TOO OLD - CRAP!
   list($phpVersion1, $phpVersion2, $phpVersion3) = explode('.', phpversion());
   if ($phpVersion1 >=4 && $phpVersion2 >= 3) {
    if (!stream_set_timeout($fp, 5)) echo 'Could not set stream timeout<p>';
    if (!stream_set_blocking($fp, 0)) echo 'Could not set stream blocking<p>';
   }

   $now = $start;
   while (!feof($fp) && $now < $start + 5) {
    $res .= fgets($fp, 4096);
    $now = time();
   }

   fclose($fp);
  }
  if (strlen($res) > 0 && $now < $start + 5) {
   echo trim(substr($res, strpos($res, '<'), strlen(trim($res))));
  } else {
   echo "${font}Could not display profiles at this time. <a 
href=http://www3.brinkster.com/soa/val/profile/view.asp>Click here</a> or try again 
later</font><p>";
  }
?>
  

Reply via email to