Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP check if file is in use

Tags:

file

php

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.

like image 537
Octavian Avatar asked Jun 14 '11 08:06

Octavian


People also ask

How will you check if a file exists or not using PHP?

The file_exists() function checks whether a file or directory exists.

What is Is_file function in PHP?

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.

What is __ DIR __ in PHP?

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.

How check if string is file PHP?

PHP is_file() Function The is_file() function checks whether the specified filename is a regular file.


1 Answers

look into flock() http://php.net/manual/en/function.flock.php

like image 110
Sabeen Malik Avatar answered Sep 30 '22 02:09

Sabeen Malik