Reputation: 41
Example, my website has module update information. The value is stored in the file a.php:
<?php
return array(
'value' => STORE_HERE
);
if two users to perform at one moment, what would happen?
how at one time, only one request is met?
Upvotes: 0
Views: 134
Reputation: 224
When the php runs the fopen with write option, if the file is already locked for writing, you should get an error, so you'll not be able to use a valid handle to write to the file.
I'd think in store the value to a db and lock the table for writting (by transactions for example) while you're using the value.
Keep in mind that storing values in a php file (which is executable by the server) can be potentially dangerous, so someone could manage to insert malicious code to it. If you do that, be sure that the user which is executing the php file doesn't have root priviledges.
Upvotes: 0
Reputation: 343
The file will be locked until everything is written. When the file is locked, no other process can access it.
But in the first place, why would you like to save data in a PHP file? A PHP file is used for processing, not data storing.
Upvotes: 1