简体   繁体   English

php中的mysql_query会阻止并发查询吗?

[英]does mysql_query in php block concurrently queries?

I have a SugarCRM installation. 我有一个SugarCRM安装。

My problem is when I do a search in sugarcrm the search query block all other queries. 我的问题是,当我在sugarcrm中进行搜索时,搜索查询会阻止所有其他查询。

Id      User         Host                   db              Command Time    State   Info
49498   sugar        xx.xx.xx.xx:59568      sugarcrm        Query   5       Sorting result  SELECT leads.id  ,leads_cstm.cedula_c,leads_cstm.numplanilla_c,leads_cstm.profession_c,leads_cstm.b
49502   sugar        xx.xx.xx.xx:59593      sugarcrm        Sleep   5               NULL

As you can see the query Id 49502 is, I presume, waiting for query 49498 to finalize. 如您所见,我认为查询ID 49502是等待查询49498完成。

first query is a search query which last a looong time to execute second query is a query for the index page 第一个查询是最后一次执行的搜索查询,第二个查询是对索引页的查询

The odd thing is that if I open two terminals and connect to mysql using the same user as my sugarcrm installation I can execute both queries concurrently but if I make a search in the browser and open a new tab and try to access the index page, that second tab hungs until the first tab completes execution or it get a timeout from server. 奇怪的是,如果我打开两个终端并以与sugarcrm安装相同的用户身份连接到mysql,则可以同时执行两个查询,但是如果我在浏览器中进行搜索并打开一个新标签并尝试访问索引页面,第二个选项卡将挂起,直到第一个选项卡完成执行或服务器超时。

I have tested this using php both as a module and as cgi. 我已经使用php作为模块和cgi对此进行了测试。

So I guess it should be something with the mysql_query function itself? 所以我想应该与mysql_query函数本身有关吗?

Any ideas? 有任何想法吗? It's very hard to optimize the db (lots of tables, lots of content) but at least the site should be able to be used concurrently... 优化数据库非常困难(很多表,很多内容),但是至少该站点应该能够并发使用...

Probably because you're using file-based sessions. 可能是因为您正在使用基于文件的会话。 PHP will lock session files while they're in used, which essentially makes all requests by a particular session to become serial. PHP将在使用会话文件时将其锁定,这实际上使特定会话的所有请求都变为串行请求。

The only ways around this are to either use session_write_close() to release the session lock on a per-script basis, after any session-changing code is complete, or implementing your own session handler which can have its own locking logic. 解决此问题的唯一方法是,在完成任何会话更改代码后,使用session_write_close()在每个脚本的基础上释放会话锁定,或者实现自己的会话处理程序(可以具有自己的锁定逻辑)。

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

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