Cesar
Cesar

Reputation: 4116

does mysql_query in php block concurrently queries?

I have a SugarCRM installation.

My problem is when I do a search in sugarcrm the search query block all other queries.

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.

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.

I have tested this using php both as a module and as cgi.

So I guess it should be something with the mysql_query function itself?

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...

Upvotes: 0

Views: 996

Answers (1)

Marc B
Marc B

Reputation: 360632

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.

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.

Upvotes: 6

Related Questions