PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
midohioit
Forum Newbie
Posts: 18 Joined: Tue Dec 05, 2006 10:19 am
Post
by midohioit » Sun Oct 25, 2009 8:38 am
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;
}
?>
markusn00b
Forum Contributor
Posts: 298 Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England
Post
by markusn00b » Sun Oct 25, 2009 9:05 am
See
this comment on the file_get_contents() function page @ php.net.
Mark.
midohioit
Forum Newbie
Posts: 18 Joined: Tue Dec 05, 2006 10:19 am
Post
by midohioit » Sun Oct 25, 2009 10:41 am
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
markusn00b
Forum Contributor
Posts: 298 Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England
Post
by markusn00b » Sun Oct 25, 2009 10:44 am
I guess you're using < PHP5?
midohioit
Forum Newbie
Posts: 18 Joined: Tue Dec 05, 2006 10:19 am
Post
by midohioit » Sun Oct 25, 2009 10:58 am
yes, it looks like 4.4.7
midohioit
Forum Newbie
Posts: 18 Joined: Tue Dec 05, 2006 10:19 am
Post
by midohioit » Sun Oct 25, 2009 8:16 pm
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