标签:span pac name data 文件 print fwrite 程序 ror
php使用flock堵塞写入文件和非堵塞写入文件
堵塞写入代码:(全部程序会等待上次程序运行结束才会运行,30秒会超时)
<?php $file = fopen("test.txt","w+"); $t1 = microtime(TRUE); if (flock($file,LOCK_EX)) { sleep(10); fwrite($file,"Write something"); flock($file,LOCK_UN); echo "Ok locking file!"; } else { echo "Error locking file!"; } fclose($file); $t2 = microtime(TRUE); echo sprintf("%.6f",($t2-$t1));
<?php $file = fopen("test.txt","a+"); $t1 = microtime(TRUE); if (flock($file,LOCK_EX|LOCK_NB)) { sleep(10); fwrite($file,"Write something"); flock($file,LOCK_UN); echo "Ok locking file!"; } else { echo "Error locking file!"; } fclose($file); $t2 = microtime(TRUE); echo sprintf("%.6f",($t2-$t1));
标签:span pac name data 文件 print fwrite 程序 ror
原文地址:http://www.cnblogs.com/jzssuanfa/p/7074216.html