在同一时间两个PHP脚本中使用相同的会话ID [英] Using same session ID within two PHP scripts at same time

查看:123
本文介绍了在同一时间两个PHP脚本中使用相同的会话ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经ocassionally检测到PHP会话一个奇怪的问题。结果
当我正在使用相同的会话ID的两个PHP脚本,第二个脚本被卡住,直到第一个完成。结果
我想这是因为试图打开同一个会话存储文件的两倍。但可能我不是正确的。结果
你永远不会赶上正常现场工作这样的效果,因为用户通常不同时打开两个或多个页面。结果
但是,如果你试图让使用的file_get_contents() A在同一网站的网页内容,你会抓住这个问题。结果
此外,我已经通过上下文复制我的饼干,所以的file_get_contents()试图重新打开已经为在调用脚本打开同一个会话。结果
至于结果,我stucked长时间运行脚本(约5-10分钟),这也禁用我用同样的SessionID /登录,打开同一站点中的任何新的一页。结果
我怎样才能解决这个问题?你有没有看到任何美丽的解决方案呢?

I have ocassionally detected a strange problem with PHP sessions.
When I am running two PHP scripts using SAME session ID, second script is stuck until first one is completed.
I guess it is because trying to open same session storage file twice. But possible I am not right.
You will never catch this effect in normal site work, because user usually didn't open two or more pages simultaneously.
However, if you try to get content of a page of the same site using file_get_contents(), you will catch this issue.
Additionally, I have copying my cookies through context, so file_get_contents() trying to re-open same session as already opened in calling script.
As result, I have stucked long-running script (about 5-10 mins) which also disables me to open any new page of same site using same sessionid / login.
How I can to resolve this issue? Did you ever see any beautiful solution for it?

推荐答案

是的,这就是所谓的会话锁定,它是正常的PHP。

Yes, this is called "session locking" and is normal in PHP.

一个解决方案是不是不使用会话,你需要持久信息只设置cookie。

One solution is not not use sessions, just set cookies for your required persistent information.

另一个解决方案是实现自己的会话处理程序:

Another solution is to implement your own session handler:

http://php.net/manual/en/session.customhandler.php

有关自定义的MySQL会议上处理的详细演练是在这里:

A detailed walkthrough about custom MySQL session handlers is here:

http://phpmaster.com/writing-custom-session-handlers/

这篇关于在同一时间两个PHP脚本中使用相同的会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆