Mario_castro
asked on
block file
Hello
I need block a file while the user edit.
any ideas?
Thanks
Mario
I need block a file while the user edit.
any ideas?
Thanks
Mario
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
After PHP opens the file using fopen, you can verify that you are the only one using it by calling flock(). If flock() returns false, that means that you could not obtain a lock on the file.
Here's the example:
<?php
$fp = fopen("/tmp/lock.txt", "w+");
if (flock($fp, LOCK_EX)) { // do an exclusive lock
fwrite($fp, "Write something here\n");
flock($fp, LOCK_UN); // release the lock
} else {
echo "Couldn't lock the file !";
}
fclose($fp);
?>
Hope that answers your question.
Here's the example:
<?php
$fp = fopen("/tmp/lock.txt", "w+");
if (flock($fp, LOCK_EX)) { // do an exclusive lock
fwrite($fp, "Write something here\n");
flock($fp, LOCK_UN); // release the lock
} else {
echo "Couldn't lock the file !";
}
fclose($fp);
?>
Hope that answers your question.
ASKER