Redriecting when Polarhome is down

Web page creation, programs, scripts, PHP, SQL?

Moderator: Moderators

Redriecting when Polarhome is down

Postby mko » Sat Jul 08, 2006 2:16 pm

SO I have this http://mko.knows.it redirected into http://www.polarhome.com:753/~mko/blog/ I want to set tthe redirectment into else host that will execute a script if Polarhome is accesable. If accesable it will redirect into my page at polarhome. So how can this ne possible?
mko
Junior Member
 
Posts: 16
Joined: Fri Jun 24, 2005 8:14 pm

Postby zoli » Sat Jul 08, 2006 7:21 pm

hi,

you may use a "function test script" that reconfigures the redirection.

Easily check every five minute if you homa page loads. If not rewite the redirection. This script needs to run on some independent host.
Regards,
Z
---
Zoltan Arpadffy
zoli
Forum Admin
Forum Admin
 
Posts: 759
Joined: Mon Sep 30, 2002 1:27 am
Location: Stockholm, Sweden

Postby mko » Sat Jul 08, 2006 7:33 pm

thanks.. even I didn't get it :roll:
mko
Junior Member
 
Posts: 16
Joined: Fri Jun 24, 2005 8:14 pm

Postby uroskn_redhat » Sun Jul 09, 2006 10:12 am

PHP is something that i'm fammiliar with, so i would write script in PHP, and with that i can help you. ;)

Well... You will need some idepended host, to host your PHP script. (http://www.free-webhosts.com -> find one with php support, webspace and bandwith doesn't matter). Direct your domain there. Now... Every time you webpage gets new visitor, the domain direct him to that PHP script. PHP script attempts to connect to polarhome, and if it's sucsefull then redirect to polarhome, otherwise display error message, or redirect to x page ;)

And if you use some kind of "cache" that is erased every hour, so that every new visitor will not have to wait 10-30 sec for first pag to load :D

I will try to write something (it would be usefull for me too).

Code i wrote this mornig:

Code: Select all
<?php
   $host = "polarhome.com";
   $port = "80";
   $sock = socket_create(AF_INET, SOCK_STREAM, TCP);
   socket_set_block($sock);
   socket_connect($sock, $host, $port);
   if  (socket_strerror(socket_last_error($sock)) == "Success") {
     echo "Ok"; // Redirect code
   }
   else {
     echo "err"; // And code again ;) 
   }
   socket_close($sock);
?>
You cant fail unless you quit.
User avatar
uroskn_redhat
Junior Member
 
Posts: 24
Joined: Wed Oct 19, 2005 1:50 am
Location: Slovenija, Slovenske Konjice, Kajuhova X ;-)

Postby zoli » Sun Jul 09, 2006 10:45 am

Uros, this is a good solution. It would be desirable to add functionality to check his homepages's url instead of polarhome web server. They are not connected and polarhome's homepage might work while redhat is down or just the web server on redhat does not work.
Regards,
Z
---
Zoltan Arpadffy
zoli
Forum Admin
Forum Admin
 
Posts: 759
Joined: Mon Sep 30, 2002 1:27 am
Location: Stockholm, Sweden

Postby mko » Sun Jul 09, 2006 2:13 pm

zoli wrote:Uros, this is a good solution. It would be desirable to add functionality to check his homepages's url instead of polarhome web server. They are not connected and polarhome's homepage might work while redhat is down or just the web server on redhat does not work.

let me see
Code: Select all
<?php
   $host = "polarhome.com";
   $port = "753";
   $sock = socket_create(AF_INET, SOCK_STREAM, TCP);
   socket_set_block($sock);
   socket_connect($sock, $host, $port);
   if  (socket_strerror(socket_last_error($sock)) == "Success") {
     echo "Ok"; // Redirect code
   }
   else {
     echo "err"; // And code again ;) 
   }
   socket_close($sock);
?>
this should check debian's mainpage?
edit: I uploaded script fot testing purposes into http://www.polarhome.com:753/~mko/index.php

and got


Warning: socket_create() expects parameter 3 to be long, string given in /home/m/mko/public_html/index.php on line 10

Warning: socket_set_block() expects parameter 1 to be resource, null given in /home/m/mko/public_html/index.php on line 11

Warning: socket_connect() expects parameter 1 to be resource, null given in /home/m/mko/public_html/index.php on line 12

Warning: socket_last_error() expects parameter 1 to be resource, null given in /home/m/mko/public_html/index.php on line 13
Ok
Warning: socket_close() expects parameter 1 to be resource, null given in /home/m/mko/public_html/index.php on line 19
mko
Junior Member
 
Posts: 16
Joined: Fri Jun 24, 2005 8:14 pm

Postby uroskn_redhat » Sun Jul 09, 2006 9:12 pm

No this does NOT check the debian mainpage. It just connect to polarhome, and print if it's ok (or not).

This code was only published to give the basic idea about the solution. It's not a solution code

And no. Do not upload this to the webpage. And as i sead before find an independent host (Host that does not have anything to do with polarhome).

P.S: Sorry for my late delays. I should be posting REAL code by now. Something came by. You get the code in the morning (i hope so).
You cant fail unless you quit.
User avatar
uroskn_redhat
Junior Member
 
Posts: 24
Joined: Wed Oct 19, 2005 1:50 am
Location: Slovenija, Slovenske Konjice, Kajuhova X ;-)

Postby uroskn_redhat » Sun Jul 09, 2006 10:08 pm

Ok... I manage to make all that i promised in the previous posts. It's done. Tested on my home server, and on the redhat server. This is the TRUE script that check debian Apache.

PHP script can be downloaded here:
http://www.polarhome.com:793/~uroskn/do ... _check.zip
klick ;)

The script connect to specific port and host you define (It's currently set to my homepage, but edit conf.php). If connection is OK redirect to the page you defined. If NOT then it can either display error message, or redirect to another host, depend on your configuration.

It also include "cache", that is erased every hour.

For more deatils about configuration look in the file conf.php
And do not forget to set the permision of the file data.php to the one that php can read (on redhat box is xx6).

Zoli: I think that it's no need to send any HTTP headers, beacause if apache is down, than in any way we can't connect to it, even if box is working ;)

Any comments? :lol:

P.S: And as i said before: find independed host

Edit: Only rewrite some instruction
You cant fail unless you quit.
User avatar
uroskn_redhat
Junior Member
 
Posts: 24
Joined: Wed Oct 19, 2005 1:50 am
Location: Slovenija, Slovenske Konjice, Kajuhova X ;-)

Postby mko » Sun Jul 09, 2006 11:40 pm

Great script, thank!
But the point is none of the free php hosts I tried were able to run the script. tripod uk http://members.lycos.co.uk/mkozel/test.php
Fatal error: Call to undefined function: socket_create() in /data/members/free/tripod/uk/m/k/o/mkozel/htdocs/test.php on line 20


awardspace.com http://mkoo.awardspace.com/hede/test.php always thinks debian is down.

I searched for other hosts at http://www.free-webhosts.com your descriped but it seems they have a ban on my IP range :oops:

Thanks again for script.
OK http://mko.my-place.us/test.php works :D
ooops
Warning: socket_create() has been disabled for security reasons in
Another host reccomendation will be useful.
mko
Junior Member
 
Posts: 16
Joined: Fri Jun 24, 2005 8:14 pm

Postby uroskn_redhat » Mon Jul 10, 2006 9:19 am

Here:

http://www.freewebsitehost.net

There i still have one webhosting account and i tested on it. It works there. Just to be sure (It direct to my homepage).

You can register your account there. However, if its your IP range banned even there, or for any other reason you can't create account, i created an additional config for you.

http://xpages.freewebsitehost.net/mko/index.php
You cant fail unless you quit.
User avatar
uroskn_redhat
Junior Member
 
Posts: 24
Joined: Wed Oct 19, 2005 1:50 am
Location: Slovenija, Slovenske Konjice, Kajuhova X ;-)

Postby mko » Mon Jul 10, 2006 4:04 pm

You are just great! I can't sign up my self because sign ups are closed. Also I've been wondering where does your config for me redirects when polarhome down. It should be http://ustkat.blogspot.com/
mko
Junior Member
 
Posts: 16
Joined: Fri Jun 24, 2005 8:14 pm

Postby uroskn_redhat » Mon Jul 10, 2006 4:25 pm

Ah... this is not a problem.

Direct your domain to the http://xpages.freewebsitehost.net/mko/index.php (my account), and i'll configure it to go on the page you defined ;)

And, beacaue i don't know where to redirect, it's currently configured to display error message. I'll filx it
You cant fail unless you quit.
User avatar
uroskn_redhat
Junior Member
 
Posts: 24
Joined: Wed Oct 19, 2005 1:50 am
Location: Slovenija, Slovenske Konjice, Kajuhova X ;-)

Postby mko » Mon Jul 10, 2006 4:33 pm

:mrgreen: Thanks a lot. All seems in order now.
http://mko.knows.it pretty cool url isn't it :)
mko
Junior Member
 
Posts: 16
Joined: Fri Jun 24, 2005 8:14 pm

Postby uroskn_redhat » Mon Jul 10, 2006 5:04 pm

Ok... It's done now.

This is how the conf.php now looks like:
Code: Select all
<?php
  $conf_here = 1; // <- DO NOT EDIT THIS
 
  // Location of the webpage that is redirected when
  // every thing is ok. Must start with http://
  $ok_loc = "http://www.polarhome.com:753/~mko/blog/";
 
  // Print error, or redirect to another page?
  // 1 = Print error | 0 = Redirect
  $err_type = 0;
 
  // Location of the webpage that is redirected when
  // something is not right. Must start with http://
  // Used if $err_type is set to 0
  $err_loc = "http://ustkat.blogspot.com/";
 
  // Error message
  // Used when $err_type is set to 1
  $err_message = "Soory... Webapge currently unavailable.";
 
  // Host we are checking
  $host_check = "polarhome.com";
 
  // Port we are checking
  $port_check = 753;
?>


Notice: Port 753 is http port for debian.

Yes... URL is cool. Did you get it from afraid.org (http://freedns.afraid.org)?
Last edited by uroskn_redhat on Tue Aug 15, 2006 12:35 am, edited 1 time in total.
You cant fail unless you quit.
User avatar
uroskn_redhat
Junior Member
 
Posts: 24
Joined: Wed Oct 19, 2005 1:50 am
Location: Slovenija, Slovenske Konjice, Kajuhova X ;-)

Postby mko » Mon Jul 10, 2006 5:08 pm

mko
Junior Member
 
Posts: 16
Joined: Fri Jun 24, 2005 8:14 pm


Return to Web development

Who is online

Users browsing this forum: No registered users and 2 guests

cron