?
Solved

block file

Posted on 2003-10-27
5
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

762 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