<?php/* idea: Given file, write read (fopen, fwrite ...) If more than 1M is to rewrite the backup to a content, determine the size, if greater than 1M, backup is less than write */class log{//define a constant, create a file name const LOGFILE = ' curr.log ';/ Write file public static function write ($cont) {$cont. = "\ r \ n"; $log = Self::isbak ();//Calculate the address of the file, judge the size $fh = fopen ($log, ' ab ');//Open, Append mode fwrite ($FH, $cont); fclose ($FH);} Backup log public static function bak () {//give the path to the file, and change the original log//to date. bak form $log = ROOT. data/log/'. self::logfile; $bak = ROOT. ' data/log/'. Date (' Ymd '). Mt_rand (10000,99999). '. bak '; return rename ($log, $bak);} Determine if the log is larger than 1Mpublic static function Isbak () {//Determine if the file exists $log = ROOT. ' data/log/'. Self::logfile;if (!file_exists ($log)) {//If not present, create the file Touch ($log);//Touch also has this command on Linux, which is to quickly build a file return $log;} Judge Size Clearstatcache (true, $log); When the cache is cleared, the. bak file is created $size = FileSize ($log), if ($size <= 1024*1024) {//If <=1m is written to return $log;}//To this line, stating greater than 1Mif (!self:: Bak ()) {return $log;} else {touch ($log); return $log;}} }? >
Extreme method Test Call, loop execution 10,000 times
Another page//introduction log function Class Mysql{public functions query ($sql) {log::write ($sql);}} $mysql = new MySQL ();/**/for ($i =0; $i <10000; $i + +) {$sql = ' select Goods_id,goods_name,shop_price from Goodsselect Goods_id,goods_name,shop_price from Goodsselect goods_id,goods_name,shop_price from Goodsselect goods_id,goods_name, Shop_price from Goodsselect Goods_id,goods_name,shop_price to goodsselect goods_id,goods_name,shop_price from goods Where goods_id= '. rand (10000,99999); $mysql->query ($sql);} Log::write (' record '); echo "Execution complete";
PHP Framework added logging function class