dongsi2317
dongsi2317
2015-06-20 19:03

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 dpn4073 6年前

    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.

    点赞 评论 复制链接分享