I want to make a flat files database which will use .php files to store data from the website. My only problem is that if when I 'select' something from the flatfile database (that means the file is read), if in that moment a 'update' is in progress (that means the file is modified and written), the file gets blank and I lose all the content.
I thought about something, to check if the file is in use at the moment, and if it is, to wait a couple of milliseconds and check again.
The file_exists() function checks whether a file or directory exists.
The is_file() function in PHP is an inbuilt function which is used to check whether the specified file is a regular file or not. The name of the file is sent as a parameter to the is_file() function and it returns True if the file is a regular file else it returns False.
The __DIR__ can be used to obtain the current code working directory. It has been introduced in PHP beginning from version 5.3. It is similar to using dirname(__FILE__). Usually, it is used to include other files that is present in an included file.
PHP is_file() Function The is_file() function checks whether the specified filename is a regular file.
look into flock()
http://php.net/manual/en/function.flock.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With