Jump to content

Exception Handling


ibanez270dx

Recommended Posts

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:

 

       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();
        }

 

...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. Can this be done? If so, how?

 

Any and all help is appreciated!

 

Thanks,

- Jeff

Link to comment
Share on other sites

Use a file_get_contents or similar to grab the contents of the URL.

 

Check for specific error text ( 404 might be a little vague and throw false positives, but it all depends on the data you expect )

 

 


$str = file_get_contents( 'http://harrier:4243/cpa?from='.$_POST['FromDate'].'&to='.$_POST['ToDate'] );

if (  strpos( $str, '404' ) === FALSE )
    echo 'Server is down, man';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.