Multiple instances of PHP script won't load co

2019-08-08 21:16发布

问题:

I'm trying to get two instances of a php script to run concurrently. I have a script, 'test.php':

<p><?php echo time(); ?> Sleeping...</p>
<?php sleep(5); ?>
<p><?php echo time(); ?> done</p>

If I load the page in two browser tabs at the same time, I get this:

1446855680 Sleeping...

1446855685 done

and this:

1446855686 Sleeping...

1446855691 done

One instance blocks until the other loads. This happens on both Firefox and Chromium.

If I make a second identical script, 'test2.php', or rewrite two urls to the same script, and load the two pages in different tabs, I get this:

1446855862 Sleeping...

1446855867 done

and this:

1446855863 Sleeping...

1446855868 done

Both instances are loading at the same time. So it is identical URLs that are being blocked.

How can I get two instances of a script with the same URL to load/run at the same time?

回答1:

As VolkerK pointed out and your testing confirmed Firefox/Chrome perform requests for the exact same URL in sequence. However in practice this is not a problem since Users usually do not load the same page twice, and for a script that serves data to Ajax requests the URLs will differ since different parameters are appended.

Should you want to bypass this mechanism in general you can append a random parameter (has to be different in the different browser tabs) to the url, i.e. url.to/your/script?urlID=4821de7e524cf762deab6ed731343466. The random parameter causes the browser to see two different URLs and thus to perform the load in parallel.