ibanez270dx Posted June 6, 2008 Share Posted June 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/109060-exception-handling/ Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 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'; Quote Link to comment https://forums.phpfreaks.com/topic/109060-exception-handling/#findComment-559500 Share on other sites More sharing options...
ibanez270dx Posted June 6, 2008 Author Share Posted June 6, 2008 thanks, but that just gives me a 500 error... any other thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/109060-exception-handling/#findComment-559518 Share on other sites More sharing options...
discomatt Posted June 6, 2008 Share Posted June 6, 2008 What's giving you the 500 error? file_get_contents? PHP version? Try using fopen/fread to get the contents Quote Link to comment https://forums.phpfreaks.com/topic/109060-exception-handling/#findComment-559533 Share on other sites More sharing options...
ibanez270dx Posted June 6, 2008 Author Share Posted June 6, 2008 I just tried using an fopen type thing - it reads that it's up when the server is up, but when it's down, it just times out. Perhaps a better way to go about this is to check if my WEBrick service is running on port 4243? Is that possible? Quote Link to comment https://forums.phpfreaks.com/topic/109060-exception-handling/#findComment-559534 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.