如何为持久的 PHP FastCGI 进程设计应用程序? [英] How to design applications for persistent PHP FastCGI processes?

查看:21
本文介绍了如何为持久的 PHP FastCGI 进程设计应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 终于 开始使用 TRUE FastCGI 实现.(不要与 PHP-FPM 或 PHP 进程 常用的启动脚本混淆使用 Nginx - 将 node.js 用于 PHP.

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?

例如,通常如果有错误或异常,应用程序会记录它,提醒用户,然后 die() 的.但是,如果您有一个(几乎)永无止境的守护进程在运行,那么您如何在结束当前请求并移动到下一个请求时处理错误?你不能继续你正在做的事情(因为错误) - 但你不能不终止进程就退出.

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.

推荐答案

例如...

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

你可以在 something() 中放入三页代码.如果代码中的任何地方发生错误,您可以简单地跳到循环的下一次迭代,而不是继续当前的迭代.

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.

这篇关于如何为持久的 PHP FastCGI 进程设计应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆