0

I might be misunderstanding what it means for nginx to be event-driven opposed to process driven (thus we don't have mod_php in every thread like Apache would). I am assuming that since I have 1 instance of php-cgi running for all the nginx worker threads that all php executions will be synchronous. Does this mean that when I access objects from the database I do not have to worry about race conditions when it comes to saving data?

Not sure if I have the correct thinking or am completely off-base.

Thanks. I am new to web-programming/database/web-servers

4

1 回答 1

0

“事件驱动”意味着应用程序“坐在那里”等待事件来驱动接下来发生的事情。典型的事件是各种形式的鼠标或键盘活动。

相反,“过程驱动”(通常是“过程编程”)仅仅意味着有一个程序“监视”事物,不断地搅动它应该做的任何事情。

你可以同时编码,但这样做是“一种高级练习”——或者,至少,有些人是这样认为的。

现在,竞争条件的大问题实际上是关于可能发生什么纠缠的问题。对于数据库,这是一个完美的例子:如果您将返回错误状态编码在全局变量中,并且代码中的活动之间存在任何时间重叠(通常发生在“事件驱动”环境中,但也可能发生在纯过程编程中)可以得到错误的错误信息。想象一下,如果一个使某事发生的线程发生了错误,而一个较快的线程没有错误,但较快的线程随后出现,并将状态设置为成功;有一种情况是“线程安全”编程可以避免的。这只是“竞争条件”的一个例子。

只要每个线程的操作都是独立的,您就没有竞争条件本身——这完全取决于应用程序的逻辑及其需求——这里没有人能告诉你它们可能是什么,只有开发人员!...这是航空公司预订系统吗?...

于 2012-02-28T00:43:20.260 回答