php写文件操作

	function writeLog($file, $msg, $mode='a+')
	{
		$fp = fopen($file, $mode);
		if(flock($fp, LOCK_EX))
		{
			fwrite($fp, $msg);
			fflush($fp);
			flock($fp, LOCK_UN);
		}
		else
			echo "Couldn't get the lock<br/>";
		fclose($fp);
	}

	$file = 'zzb.log';
	writeLog($file, "1. this is the first message\n");
	writeLog($file, "2. this is the first message\n");
	writeLog($file, "3. this is the first message\n");
	writeLog($file, "--------------------\n\n");

  

posted on 2015-04-16 16:47  清清飞扬  阅读(207)  评论(0编辑  收藏  举报