2

PHP is finally starting to get TRUE FastCGI implementations. (Not to be confused with PHP-FPM or PHP process startup scripts commonly used with Nginx - think node.js for PHP.

How do you design applications with these new, asynchronous patterns opening up?

For example, usually if there is an error or exception the app logs it, alerts the user, and die()'s. However, if you have a (almost) never-ending daemon running then how do you handle errors while ending the current request and moving to the next? You can't just continue with what you were doing (because of the error) - yet you can't exit without killing the process.

Community
  • 1
  • 1
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
  • http://simas.posterous.com/writing-a-php-daemon-application – Xeoncross Aug 29 '11 at 23:48
  • You can catch an error, log it, then continue on if you write the code to do so. – dqhendricks Aug 30 '11 at 01:11
  • @dqhendricks, if you just encountered a database exception - how ***do*** you just log it and continue on? After you are done with your error handling PHP is going to go right back to where you were before the error happened and try to run the rest of the code. – Xeoncross Aug 30 '11 at 01:16
  • if that is what happens, then perhaps you are not catching exceptions far enough out in your code. you can write it to do whatever you want. that's the beauty of exceptions. – dqhendricks Aug 30 '11 at 01:23

1 Answers1

3

for instance...

while(1) {
   try {
      something();
   catch (Exception) {
      log();
   }
}

you could put three pages of code in something(). if an error happens anywhere in that code, you could simply skip to the next iteration of the loop instead of continuing on with the current iteration.

dqhendricks
  • 19,030
  • 11
  • 50
  • 83
  • Your totally right! Sorry @dqhendricks, it's been a long day and I'm having trouble thinking. If I wrap the entire app in a `try {} catch` block there is no trouble. Perfect. – Xeoncross Aug 30 '11 at 01:36