Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Can Anyone Help Me Detecting 503 Errors In Php Progs ?
Sten
post Feb 4 2008, 09:55 AM
Post #1


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



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!
Go to the top of the page
 
+Quote Post
turbopowerdmaxst...
post Feb 4 2008, 10:50 AM
Post #2


Premium Member
Group Icon

Group: [HOSTED]
Posts: 367
Joined: 16-February 06
From: Kolkata, India
Member No.: 11,322



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;
?>


Go to the top of the page
 
+Quote Post
yordan
post Feb 4 2008, 12:19 PM
Post #3


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 1,969
Joined: 16-August 05
Member No.: 7,896



@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
Go to the top of the page
 
+Quote Post
Sten
post Feb 5 2008, 06:53 AM
Post #4


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



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.
Go to the top of the page
 
+Quote Post
TavoxPeru
post Feb 8 2008, 01:20 AM
Post #5


Super Member
Group Icon

Group: [HOSTED]
Posts: 740
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



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,
Go to the top of the page
 
+Quote Post
Sten
post Feb 8 2008, 01:42 AM
Post #6


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



Thanks, that works now!

I added
CODE
else
{
echo " 0";
}

to it so that it shows 0 if it can't find it!
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Windowsxp Is Not Detecting My Dvd Writer Correctly(8)
  2. CD-RW Drive Blues(10)
  3. Board Throws Errors In Firefox(5)
  4. Multislot Usb Memory Card Readers(6)
  5. MySQL Errors? - Error 13!(0)
  6. Install Errors.(3)
  7. How To Repair Disk Errors And Bad Sectors(2)
  8. Detecting XHTML + XML In Browsers(1)
  9. Post Your Funniest Software Errors!(4)
  10. Access Errors When Freeing Memory(7)
  11. Problem Accessing My Cpanel(8)
  12. IE7 Beta - Usual Microsoft Comedy Of Errors?(13)
  13. CentOS: Test Server Reporting Errors!(5)
  14. Strange IPB 2.1.4 Errors While Sending PM(5)
  15. Group Errors(4)
  1. Detecting Wirless Networks(12)
  2. Error Log From Forum Errors(0)
  3. OSCommerce Errors(5)
  4. Crc Errors In Cd(5)
  5. Read Errors With External Harddrive(6)
  6. Errors On Astahost Forum(2)
  7. Installing Ipb Help(5)
  8. Php Mysql Errors(2)
  9. Help! Pc Not Detecting Video Card(10)
  10. Cute News Errors!(0)
  11. Strange Errors With Servers?(6)
  12. Errors When Installing/booting(13)
  13. Phpmyadmin Continues To Have Errors.(17)


 



- Lo-Fi Version Time is now: 22nd August 2008 - 05:11 AM