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.

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

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图