Parallel Ajax request and session locking

Yesterday, I was running into a weird issue when I was making parallel ajax requests to my php server running CodeIgniter MVC framework. Let me explain: I had two controller methods A and B. Method A was executing a long action (io and network bound) and was updating database with its progress at regular intervals. Method B was retrieving this progress status from the database and presenting it in html format. I had setup the following jquery ajax calls 

a) A call to method A

b) A call to method B every 2 seconds. 

The idea was to update the UI with the results from method B while A is being performed. This way the user is cognizant of the progress of this long action. The issue I was running into was that method B never returned until method A was complete. When I investigated these requests in chrome I observed that request issued by method B was tagged as “pending” in chrome.

After much research I concluded that the issue was due to php session locks. PHP session doesn’t allow another script to run unless an existing script completes its execution. 


Solution: The solution is to explicitly close the PHP session after you are done with using the PHP session variables. In my case I closed the php session as soon as I entered method  A and re opened it at the end of method B. Note, you won’t be able to update any variables unless you open the session again. 


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s