-->

How to design applications for persistent PHP Fast

2019-05-27 03:00发布

问题:

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.

回答1:

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.