views:

27

answers:

1

I'm using Firefox 3.6.6.

I have a PHP script called index.php with the following code:

<?php
sleep(20); die(time());
?>

I open two browser tabs, copy the URL into each of them, and then quickly hit enter in each tab. The first tab completes in just over 20 seconds. The second tab completes in just over 40 seconds.

I do the same experiment in IE and both scripts complete within a second of each other, around 20 seconds.

Is this expected behavior? The actual script that caused me to test this is a synchronous procedure. I want any person attempting to execute it twice to receive an error that the process is already in progress, rather than having the browser sit there and wait until it can execute it a second time.

If this is how Firefox works, how does it determine when a page is a duplicate and that it should queue up the requests rather than run them simultaneously?

I can fool it by putting a junk GET string on the end, e.g. index.php and index.php?JUNK=1 both complete at around 20 seconds.

+2  A: 

It's the caching mechanism: if you disable all caching the problem does not occur. Apparently, the FF developers have a check that when a request is still loading it might be cachable, so it waits for the first, only then decides not to use cache, and only then dispatches the second request (you can check that in the timestamp of your log files).

You could try to play around with some no-cache headers & a flush() of data to the client, perhaps it can determine caching is not an option when receiving headers, although I suspect the cache check is done only after the content is loaded.

Wrikken