简体   繁体   English

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

[英]Does one PHP/application session correspond to one Oracle/database session?

I'm experiencing some behavior I did not expect. 我遇到了一些我没有想到的行为。 I have a synchronous procedure that is kicked off via PHP/OCI8. 我有一个通过PHP / OCI8启动的同步过程。 At the beginning of the process there is a SELECT...FOR UPDATE NOWAIT 在该过程的开始,有一个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. 我做NOWAIT因为我希望用户与该进程已经运行,而不是他们的浏览器等待锁定的错误消息立即通知。

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 . 当我从具有两个单独的PHP会话的两台不同的计算机上运行该进程时,我得到了预期的行为:一个运行,而另一个运行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 . 但是,当我在同一浏览器上打开两个选项卡并运行该过程时,第二个选项卡等待30秒以上的时间来完成第一个选项卡,然后运行第二个选项卡-好像我没有指定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. 我认为一个单独的HTTP请求(执行单独的PHP => Oracle连接)将给我单独的数据库会话。 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? 更新:我发现了这一点:在#6, 如何使用OCI8扩展名连接到Oracle下的http://wiki.oracle.com/page/PHP+Oracle+FAQ 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. 如果在脚本或httpd服务器会话中多次使用相同的用户凭据,则PHP将共享/重用连接。 You can use the oci_new_connect() function to ensure a new session is used. 您可以使用oci_new_connect()函数来确保使用新会话。 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). 调用oci_pconnect()函数建立一个在脚本结束时未关闭的持久连接(使下一个脚本中的重新连接更快)。

However, when I change to oci_new_connect it does not fix the issue. 但是,当我更改为oci_new_connect它不能解决问题。 Different sessions on different computers throw the ORA-00054 , but two tabs on the same browser synchronize access but do not respect the NOWAIT . 不同计算机上的不同会话会抛出ORA-00054 ,但是同一浏览器上的两个选项卡会同步访问,但不遵循NOWAIT

Remember, there is "loadsession" and then there is "savesession" 记住,有“ loadsession”,然后有“ savesession”

It is possible that another process udpates the php session in this interval depending on how your session driver works. 根据您的会话驱动程序的工作方式,另一个进程可能会在此时间间隔内覆盖php会话。

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. 取而代之的是,Firefox 3.6.6将我的同时请求排队了,而这毕竟不是PHP或DB会话问题。 See this question for an exploration of that issue: Does Firefox synchronize requests for the same page? 请参见以下问题,以探索该问题: Firefox是否同步对同一页面的请求?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM