0

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!

7
  • the first process might be getting a write lock on the file, try opening the file in read only mode in the second process. Commented Nov 17, 2016 at 15:34
  • All these aspects are discarded. I've tried to open the file in read mode, append mode, write mode, etc. with no luck. Furthermore, the fact that an echo "hello"; does not work neither has nothing to do with the file lock. Thank you anyway for your comment! Commented Nov 17, 2016 at 15:40
  • 1
    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. Commented Nov 17, 2016 at 15:44
  • I will give a try to the session-locking you say. As I said, the echo "hello"; exit; does not try to read the file, so if the file is locked or not, should not be relevant for the page not to echo "hello", because nothing else is executed but this echo. Thanks for your help! Commented Nov 17, 2016 at 15:47
  • As @TimAagaard said, it seems to be the session-locking as when I use session_write_close(); it makes it work (few times). I will make more tests so I know where to put it so it works most of the times. Thank you! Commented Nov 17, 2016 at 15:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.