Search found 3 matches
- Wed Mar 19, 2008 2:39 am
- Forum: PHP - Security
- Topic: Mutual Exclusions
- Replies: 5
- Views: 2119
Re: Mutual Exclusions
I think flock can be used for this, because flock has an internal queueing mechanism for processes that try to access a specified file. Just create a file to be used for requesting a lock on via flock() function, then you'll be put to the tail of the queue. You'll wait until all the previous lock re...
- Tue Mar 18, 2008 4:37 pm
- Forum: PHP - Code
- Topic: File Locking in PHP: Do a LOCK_EX request "suspend" until ok
- Replies: 1
- Views: 198
Re: File Locking in PHP: Do a LOCK_EX request "suspend" until ok
the answer comes from the inquirer himself; yes it does. to test it out run the script below twice simultaneously. <?php $fp = fopen("ftest.txt", "w"); if (flock($fp, LOCK_EX)) { echo "Got it!\n"; sleep(8); flock($fp, LOCK_UN); } ?>
- Mon Mar 17, 2008 12:51 pm
- Forum: PHP - Code
- Topic: File Locking in PHP: Do a LOCK_EX request "suspend" until ok
- Replies: 1
- Views: 198
File Locking in PHP: Do a LOCK_EX request "suspend" until ok
Look at the example below flock($fp, LOCK_EX); // do an exclusive lock fwrite($fp, "Write something here\n"); flock($fp, LOCK_UN); What happens if an exclusive lock on the file is already being hold by another user? Does this script suspend until the other user leaves the lock? If not, wha...