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?...

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

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类