Page 1 of 1

Time out error

Posted: Sun Oct 25, 2009 8:38 am
by midohioit
Can anyone tell me a good way to avoid the issue im having. I need to change the timeout to be around like 5 seconds or so. I get a timeout on one of the websites, it is the same one all the time and does not take long to load in my browser. The return code is always 408 and i think I just need to add code for it to take just a few seconds longer. Does anyone have any ideas. I tried to use a few things but nothing seems to work. Thanks in advance.

-charles

Code: Select all

 
<?php
 
$arr = array("websitearray" => 
           array(                      1  =>  "http://www.google.com", 
                  2  =>  "http://www.msn.com", 
                  3  =>  "http://www.yahoo.com"
                )
            );
 
 
 
 
 
$site_count = 3;
$loop_count = 1;
 
while ($loop_count <= $site_count)
{
 
  $current_site = $arr["websitearray"][$loop_count]; 
  $get = file_get_contents($current_site);
  
 
 // 404: Not Found
 // 409: Conflict
 // 408: Request Timeout
 // 500: Internal Server Error
 // 503: Service Unavailable
  if ( (preg_match('#404#', $get)) || (preg_match('#409#', $get)) || (preg_match('#408#', $get))
       || (preg_match('#500#', $get))|| (preg_match('#503#', $get)) )
  {
   echo "$current_site has errors and has failed to load <img src='images/CheckMarkX.jpg'> ";
   if (preg_match('#404#', $get)) { echo "Return Code is: 404 <br><br>";  }
   if (preg_match('#409#', $get)) { echo "Return Code is: 409 <br><br>";  }
   if (preg_match('#408#', $get)) { echo "Return Code is: 408 <br><br>";  }
   if (preg_match('#500#', $get)) { echo "Return Code is: 500 <br><br>";  }
   if (preg_match('#503#', $get)) { echo "Return Code is: 503 <br><br>";  }
  }
  else
  {
   echo "$current_site has passed successfully:  <img src='images/green_check.jpg'> <br><br>";
    
  }
 $loop_count = $loop_count + 1;
}
 
 
?>
 

Re: Time out error

Posted: Sun Oct 25, 2009 9:05 am
by markusn00b
See this comment on the file_get_contents() function page @ php.net.

Mark.

Re: Time out error

Posted: Sun Oct 25, 2009 10:41 am
by midohioit
Mark,

Thanks for your help. It does seem to pass now but i get the following warning:

Warning: file_get_contents() expects at most 2 parameters, 3 given

Code: Select all

 
  $current_site = $arr["websitearray"][$loop_count]; 
  
  $ctx = stream_context_create(array( 
    'http' => array( 
        'timeout' => 1 
        ) 
    ) 
); 
 
$get = file_get_contents($current_site, 0, $ctx); 
 
I even tried taking out the 0 but then get a warning about it expect the 2nd to be a boolen

Re: Time out error

Posted: Sun Oct 25, 2009 10:44 am
by markusn00b
I guess you're using < PHP5?

Re: Time out error

Posted: Sun Oct 25, 2009 10:58 am
by midohioit
yes, it looks like 4.4.7

Re: Time out error

Posted: Sun Oct 25, 2009 8:16 pm
by midohioit
any other sugguestions? I dont even have to do the code and methods im doing now however id like to since the only issue is the timeout issue