due to the fact how a Server can handle requests (-> Simultaneous Requests to PHP Script), I have a question about what can happen, if a script checks a filename and then saves the file.
For example: User A requests "save.php". A really short time later User B requests "save.php". The script of User A is at the point where the script checks if the file exists. The file does not exist and BEFORE the file is written, User B's script is at the point where it checks the existing of the file. So it also says that the file does not exist. Now User A's script writes the file. And User B's script overwrites the file, if they have the same filename. (Filename is random, but this can happen).
How can I avoid such things? Is there something like Tablelocking and Transactions for PHP-command? Is it possible that User B's script outruns User A's script, because it gets more ressources from the server?
Best regards