Touching server before executing a URL (Exception Handling)
Posted: Fri Jun 06, 2008 5:56 pm
Hello,
I have a PHP page that basically just takes some user input (dates) and puts them into a URL which points to a WEBrick server and initializes some Ruby scripts. Everything works perfectly fine, with one exception. I want to ensure that when my WEBrick server gets kicked or is down for some reason, that PHP can realize it and act accordingly. I tried some basic PHP exception handling, but to no avail. What I have is this:
...which leaves me with a 404 if my WEBrick server is down. Thus, I suppose I need PHP to "touch" and ensure the WEBrick server is alive before executing the META refresh tag. I got a suggestion to try file_get_contents like so:
...but that doesn't work either and just gives me a 500 error. Can this be done? If so, how?
Any and all help is appreciated!
Thanks,
- Jeff
I have a PHP page that basically just takes some user input (dates) and puts them into a URL which points to a WEBrick server and initializes some Ruby scripts. Everything works perfectly fine, with one exception. I want to ensure that when my WEBrick server gets kicked or is down for some reason, that PHP can realize it and act accordingly. I tried some basic PHP exception handling, but to no avail. What I have is this:
Code: Select all
try
{
echo "<META http-equiv=\"refresh\" content=\"0;URL=http://harrier:4243/cpa?from=$_POST[FromDate]&to=$_POST[ToDate]\">";
exit;
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
Code: Select all
$str = file_get_contents( 'http://harrier:4243/cpa?from=2008-06-01&to=2008-06-10' );
if ( strpos( $str, '404' ) === FALSE )
{
echo 'The Server is Down';
}
else
{
echo 'The Server is Up';
}
Any and all help is appreciated!
Thanks,
- Jeff