php如何解决多线程同时读写一个文件的问题

<?php
header("content-type:text/html;charset=utf-8");

  $fp = fopen("lock.txt","w+"); 

    if(flock($fp, LOCK_EX)){// 进行排它型锁定 
        fwrite($fp,"Write something here\n"); 
        flock($fp, LOCK_UN);// 释放锁定 
    }else{ 
        echo "Couldn't lock the file !"; 
    } 

    fclose($fp); 
?>

 source:http://www.bcty365.com/content-10-2954-1.html

posted @ 2016-02-01 15:08  侠岚之弋痕夕  阅读(776)  评论(0编辑  收藏  举报
Where is the starting point, we don't have a choice, but the destination where we can pursue!