Astahost.com   Mar 19, 2010
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Can Anyone Help Me Detecting 503 Errors In Php Progs ?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Can Anyone Help Me Detecting 503 Errors In Php Progs ?

Sten
Sorry for being a pain and not knowing much PHP, I'm not that brilliant at it.

Anyway, can anyone help me with this little code?

<?php
$online = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action") or die(" 0");
$onlinee = trim(strip_tags($online));
echo $online;
?>

All it does is show how many people are online on Habbo Australia. It works, except when Habbo is down (it is now because the servers carked it) it gives me this.

Warning: file_get_contents(http://www.habbo.com.au/habbo_count_xml.action) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable in /home/habfront/public_html/templates/habbo_front_1/index.php on line 132

It still shows the 0 for when it dies except how do I get it not to show the error?

There's also another problem with it, well I'm using Joomla and when Habbo is down, along with the error, it also stops the component and modules and that from showing which is really annoying.

So how do I make it so it doesn't show the error and just shows the 0 and the whole site will work properly?

Once again, I'm a PHP nub!

 

 

 


Comment/Reply (w/o sign-up)

turbopowerdmaxsteel
Use the error_reporting() function to set the error_reporting directive as follows:-

Disable: error_reporting(0);
Enable: error_reporting(1);

Use this before the block you want to disable error reporting. You should however turn it back on, otherwise all errors will go undetected.


CODE
<?php
error_reporting(0);  // Disable Error Reporting
$online = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action") or die(" 0");
error_reporting(1); // Turn it back on
$onlinee = trim(strip_tags($online));
echo $online;
?>



Comment/Reply (w/o sign-up)

yordan
@turbopowerdmaxsteel : great idea, disabling and re-enabling error reporting !
@Sten : I touched your topic title in order to make it more specific, feel free to correct it if I misunderstood it.
Yordan

Comment/Reply (w/o sign-up)

Sten
That works, it doesn't show the error!

Except... it's still stopping the modules and component and the Joomla header and everything else after it from loading.

Which basically means that when Habbo is down, my site is down which is quite annoying. I know other fansites use the same code and it doesn't do it for them, but they aren't using a CMS, the most they use is Cutenews for their news.

Anyone know how to make it load other things? PHP (well the Joomla things) and anything (content and images etc) after the code doesn't show.

Comment/Reply (w/o sign-up)

TavoxPeru
QUOTE(Sten @ Feb 5 2008, 01:53 AM) *
That works, it doesn't show the error!

Except... it's still stopping the modules and component and the Joomla header and everything else after it from loading.

Which basically means that when Habbo is down, my site is down which is quite annoying. I know other fansites use the same code and it doesn't do it for them, but they aren't using a CMS, the most they use is Cutenews for their news.

Anyone know how to make it load other things? PHP (well the Joomla things) and anything (content and images etc) after the code doesn't show.

I guess that it stops because you use the die() function, the file_get_contents() function returns a string with the contents of the file on success and FALSE on failure, so, instead try the following:
CODE
<?php
error_reporting(0);  // Disable Error Reporting
$online = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action");
error_reporting(1); // Turn it back on
if ($online) {
  $onlinee = trim(strip_tags($online));
  echo $onlinee;
}
?>

Best regards,

 

 

 


Comment/Reply (w/o sign-up)

Sten
Thanks, that works now!

I added
CODE
else
{
echo " 0";
}

to it so that it shows 0 if it can't find it!

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Detecting 503 Errors Php Progs

  1. Php Mysql Errors - Fetching arrays (2)
  2. Detecting XHTML + XML In Browsers - Can it be improved? (1)
    I have written a script to detect if the mime-type application/xhtml+xml is supported in browsers,
    yet some browsers that do support this mime-type have to be tested manually so I was wondering
    whether there was a better method. Something I would rather do is intercept the browser before it
    decides to download the page instead, is this possible? Here's the script I wrote, which
    detects strings from the User Agent, it's just a small snippet of it: CODE // function to
    test for application/xhtml+xml mime-type support function CheckXHTML() {  // For Robots,...



Looking for detecting, 503, errors, php, progs,



See Also,

*SIMILAR VIDEOS*
Searching Video's for detecting, 503, errors, php, progs,
advertisement




Can Anyone Help Me Detecting 503 Errors In Php Progs ?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com



Creative Commons License