dongsi2317 2015-06-20 19:03
浏览 49
已采纳

Apache index.php文件与全局变量的并发问题?

I have used SLIM framework in PHP to implement some REST APIs. All the REST API code is in index.php, where I am using a global variables. Each of the REST API function sets a global variable, and another child function reads it. Now the reason to choose global variable is to not pass this variable from one function to another, nothing else.

I wanted to know if there could be concurrency problem, where two REST requests interleave? Is it that a single object of this index.php (OOPS) is instantiated for all the requests?

Is this how this sequence of event look like?

Request 1 -> Set global var to '10'
Request 2 -> Set global var to '9'
Request 1 -> Reads global var as '9'
Request 2 -> Reads global var as '9'
  • 写回答

1条回答 默认 最新

  • dpn4073 2015-06-21 09:50
    关注

    No, it's not an issue. In PHP, global variables are unique to the specific request. You cannot alter or read variables from another request, except by using sessions.

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

报告相同问题?