Unapedra Unapedra - 23 days ago 12
PHP Question

PHP - Multiple scripts at once (AJAX)

After asking this question, someone pointed on the right direction of not being able to execute a second script at all if one was already running.

I usually make apps which rely on the execution of AJAX calls to PHP pages, and today I found that trying to write on a file with

fwrite()
on a PHP script and trying to read that same file with
fread()
(to get progress feedback) on another AJAX call ended up in the second script only being executed when the first one had already finished.

Even trying to echo a simple "hello" (
echo "hello"; exit;
) would not show nothing on the page until the first script was finished.


So, I'm asking: is this a normal configuration? Is this the same on every installation of PHP by default? Is some configuration on
php.ini
that I can change?

Or it has to do with the server (in my case, Microsoft IIS 10)? Can someone shed some light on how to be able to execute multiple PHP scripts on different AJAX calls at once (or before the others finish)?

I know I'm not giving much information about the settings of my context, but I don't know neither where to look into.

Thank you everyone for your time and help!

Answer

As Luis said it could be a write-lock on the file that you're trying to modify. However another possibility if you're using sessions that use files (rather than a database), or a framework that uses file-based-sessions - then this behavior could also be a result of session-locking. My money would be on Luis' answer though - you should probably be using a database rather than a file unless you have a solid reason not to.