一个 PHP/应用程序会话是否对应一个 Oracle/数据库会话?

发布于 2024-09-11 03:35:30 字数 1034 浏览 9 评论 0原文

我遇到了一些我没有预料到的行为。我有一个通过 PHP/OCI8 启动的同步过程。在流程开始时有一个 SELECT...FOR UPDATE NOWAIT

我这样做 NOWAIT 因为我希望用户立即收到一条错误消息通知该流程已在运行,而不是让他们的浏览器等待锁定。

当我从两台单独的计算机上使用两个单独的 PHP 会话运行该进程时,我得到了预期的行为:一台运行,而另一台收到 ORA-00054: Resource busy and acquire with NOWAIT specified

但是,当我在同一个浏览器上打开两个选项卡并运行该进程时,第二个选项卡会等待第一个选项卡 30 秒以上完成,然后运行第二个选项卡 - 就好像我没有指定 NOWAIT< /代码>。

我没有使用任何类型的持久连接或连接池。我认为一个单独的 HTTP 请求,执行单独的 PHP=>Oracle 连接,会给我单独的数据库会话。难道不是这样吗?

更新:我发现了这个:http://wiki.oracle .com/page/PHP+Oracle+FAQ 下的 #6,如何使用 OCI8 扩展连接到 Oracle? 它说:

PHP 将共享/重用连接,如果 使用相同的用户凭据 在脚本或 httpd 中多次 服务器会话。您可以使用 oci_new_connect() 函数确保 使用新会话。致电 oci_pconnect() 函数创建一个 持久连接不是 在脚本末尾关闭 (在接下来的时间重新连接 脚本速度更快)。

但是,当我更改为 oci_new_connect 时,它并没有解决问题。不同计算机上的不同会话会引发 ORA-00054,但同一浏览器上的两个选项卡会同步访问,但不遵守 NOWAIT

I'm experiencing some behavior I did not expect. I have a synchronous procedure that is kicked off via PHP/OCI8. At the beginning of the process there is a SELECT...FOR UPDATE NOWAIT

I do NOWAIT because I want users notified immediately with an error message that the process is already running, rather than having their browser wait for the lock.

When I run the process from two separate computers with two separate PHP sessions, I get the expected behavior: one runs while the other gets an ORA-00054: resource busy and acquire with NOWAIT specified.

But when I open two tabs on the same browser and run the process, the second tab waits the 30+ seconds for the first one to finish, and then runs the second one -- it's as if I did not specify NOWAIT.

I'm not using persistent connections or connection pooling of any kind. I thought a separate HTTP request, executing separate PHP=>Oracle connections, would give me separate DB sessions. Is this not the case?

UPDATE: I found this: http://wiki.oracle.com/page/PHP+Oracle+FAQ under #6, How do I connect to Oracle with the OCI8 extension? it says:

PHP will share/re-use connections if
the same user credentials are used
more than once in a script or httpd
server session. You can use the
oci_new_connect() function to ensure a
new session is used. Call the
oci_pconnect() function to make a
persistent connection that isn't
closed at the end of the script
(making the reconnection in the next
script much faster).

However, when I change to oci_new_connect it does not fix the issue. Different sessions on different computers throw the ORA-00054, but two tabs on the same browser synchronize access but do not respect the NOWAIT.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早茶月光 2024-09-18 03:35:30

请记住,有“loadsession”,然后有“savesession”。

另一个进程可能会在此间隔内更新 php 会话,具体取决于会话驱动程序的工作方式。

Remember, there is "loadsession" and then there is "savesession"

It is possible that another process udpates the php session in this interval depending on how your session driver works.

玩物 2024-09-18 03:35:30

好的,所以这根本不是数据库问题。相反,Firefox 3.6.6 似乎对我的并发请求进行了排队,这毕竟不是 PHP 或 DB 会话问题。请参阅此问题以探索该问题:Does Firefox Synchronize requests for the同一页面?

Okay, so this is not a database issue at all. It seems instead that Firefox 3.6.6 queued my simultaneous requests and it wasn't a PHP or DB session issue after all. See this question for an exploration of that issue: Does Firefox synchronize requests for the same page?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文