?
Solved

block file

Posted on 2003-10-27
5
Medium Priority
?
213 Views
Last Modified: 2006-11-17
Hello

I need block a file while the user edit.

any ideas?

Thanks

Mario
0
Comment
Question by:Mario_castro
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
rstorey2079 earned 200 total points
ID: 9629176
Try using flock() function.  There is an example here: http://us2.php.net/manual/en/function.flock.php
0
 

Author Comment

by:Mario_castro
ID: 9629713
and when verify that the file is lock?
0
 
LVL 1

Expert Comment

by:rstorey2079
ID: 9629761
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.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question