douyingzhan5905 2012-02-28 00:32
浏览 170
已采纳

Nginx与非线程安全的PHP ...我可以在坚持没有竞争条件的情况下进行编码吗?

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

  • 写回答

1条回答 默认 最新

  • douza1373 2012-02-28 00:43
    关注

    "Event driven" means that the application "sits there" waiting for events to drive what happens next. Typical events are various forms of mouse or keyboard activity.

    In contrast, "process driven" (often "procedural programming") merely means that there's a program "watching" for things, constantly churning through whatever it is it's supposed to do.

    You CAN code both at the same time, but doing so is "an advanced exercise" - or, at least, some think so.

    Now, the big issue of race conditions is really all about the question of what entanglement may happen. With databases, here's a perfect example: If you code your return error status in a global varriable and there's ANY temporal overlap between activities in your code (often happens in "event driven" environments, but can happen in purely procedural programming, too) you can get the wrong error message. Imagine if a thread that made something happen had an error and a faster thread had no error, but the faster thread came afterwards, and set status to success; there's a condition that "thread safe" programming would avoid. This is but one example of a "race condition."

    So long as each thread's actions are independent, you don't have race conditions per-se - it all depends on the application's logic and the needs thereof - and nobody here can tell you what they may be, only the developer! ...Is this an airline reservation system?...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样