views:

108

answers:

3

Hello all,

I know PHP scripts can run concurrently, but I notice that when I run a script and then run another script after it. It waits for the first to finish and then it does what it has to do?

Is there an Apache config I have to change or do I use a different browser or something?!!

Thanks all

EDIT

If I go to a different browser, I can access the page/PHP script I need?! Is this limiting the number of requests by browser? Apache?

A: 

If you run php under fastcgi you can probably avoid this restriction.

ternaryOperator
+2  A: 

Two things comes to mind:

  1. HTTP 1.1 has a recommend maximum limit of 2 simultaneous connections to any given domain. This would exhibit the problem where you can only open one page on a site at a time unless you switch browsers.
    Edit: This is usually enforced by the client, not the server

  2. If your site uses sessions, you'll find out that only one page will load at a time...
    ...unless you call session_write_close(), at which point the second page can now open the now-unlocked session file.

R. Bemrose
Very Interesting. I didn't know those two facts. What if the second request isn't going to write any session data but use it. PHP pauses regardless is there is a session_start anywhere in the script?
Abs
For point 1 - how can I increase this recommended limit?
Abs
I believe session_write_close() still allows you to read session values, but I haven't tested it (we don't use PHP where I work).For point 1, you can't really... it's the client that does this. On Firefox, I believe the FasterFox plugin can do it. IE uses a registry key: http://support.microsoft.com/kb/282402
R. Bemrose
+1 because it's probably #2. I've never known any web server actually enforce #1.
Ben James
@Ben James: Yes, #1 is usually enforced by the client. I've added a note about that to the answer.
R. Bemrose
@R. Bemrose - I would use that function but the thing is the first script takes quite a while to finish and has to make use of session variables throughout. So the second has to just wait. I probably have to rewrite some parts of my script.
Abs
@R. Bemrose Would I have the same problem using a database based session? Or will the DB sort out the problem of concurrency? It should allow me to read multiple times without changing variables I guess?
Abs
@Abs: I'm not sure. I haven't really worked with PHP's database-based sessions. I would assume a DB-based session wouldn't lock, though.
R. Bemrose
A: 

I haven't had this problem with apache / php, the project I work on runs 3 iframes each of which is a php script + the main page, apache handles all 4 at the same time.

You may want to check your apache configuration and see how the threading is setup.

This article may help: http://www.devside.net/articles/apache-performance-tuning

Jim Ford