7月 022012
 

 
  1. <?php
  2. $lock_file = "/tmp/logging.lock";
  3. if($should_do_sth) {
  4.     $fp = @fopen($lock_file"w+");
  5.     if ($fp && flock($fp, LOCK_EX)) {
  6.         do_sth();
  7.         flock($fp, LOCK_UN);
  8.         fclose($fp);
  9.         @unlink($lock_file);  // 1.  这里删除自己创建的文件,避免因属主权限问题导致其他进程无法打开该所文件 2. 这里也可能多进程间重复删除,所以使用 @
  10.     }
  11. }
 Posted by at 上午 4:31

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据