Allow multiple instances of a php script to run
Asked Answered
B

1

5

I'm trying to use ajax to make multiple simultaneous requests to a php script, however, it only seems to do 1 instance at a time and I cannot connect to do the next call until the previous one is finished. What do I have to do in order to make it do them all at the same time? I'm using apache (xampp) on windows. I've also tested this on my unix server and the same thing is happening there as well.

Bellona answered 18/7, 2010 at 19:12 Comment(1)
I very much doubt that your server is only allowing one connection at a time. It's much more likely that you're doing something wrong in your JavaScript - can you post it?Craver
B
15

In theory, there is nothing preventing one PHP script from being executed several times in parallel -- else, a lot of websites would have big problems ;-)

So, there is probably, in your situation, some locking mecanism that prevents this...


If your script is using sessions, and those are file-based *(which is the default)*, those sessions could cause that kind of problem : with the default session handler, it's not possible to have several files accessing the same session data *(i.e. the session data that corresponds to a given user)* at the same time ; that's to prevent one script from overriding the data of another, and should probably not be disabled.

So, if your script is using sessions : would it be OK for you to stop using sessions ?
If not, you should try to close them as soon as you don't need them -- to unlock the files that are used to store them.

Here's a quote from the manual page of session_write_close, about that :

Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time.
When using framesets together with sessions you will experience the frames loading one by one due to this locking.
You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.

Bravar answered 18/7, 2010 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.