ʹÓÃphp»ñÈ¡´óÎļþÖ¸¶¨ÐÐÊýµÄÎļþÄÚÈÝ
·Ï»°ÉÙ˵£¬Ö±½ÓÉÏ´úÂ룺
<?php $file = "./logs/".date('Ymd', time()).".log"; function getFileLines($file) { $line = 0 ; $fp = fopen($file, 'r') or die("open file failure!"); if($fp){ while(stream_get_line($fp,8192,"\n")){ $line++; } fclose($fp); } return $line; } echo $lines = getFileLines($file); //·µ»ØÎļþ´ÓXÐе½YÐеÄÄÚÈÝ(Ö§³Öphp5¡¢php4) function getFileLinesContent($filename, $startLine = 1, $endLine=50, $method='rb') { $content = array(); $count = $endLine - $startLine; if(version_compare(PHP_VERSION, '5.1.0', '>=')){// ÅжÏphp°æ±¾£¨ÒòΪҪÓõ½SplFileObject£¬PHP>=5.1.0£© $fp = new SplFileObject($filename, $method); $fp->seek($startLine-1);// תµ½µÚNÐÐ, seek·½·¨²ÎÊý´Ó0¿ªÊ¼¼ÆÊý for($i = 0; $i <= $count; ++$i) { $content[]=$fp->current();// current()»ñÈ¡µ±Ç°ÐÐÄÚÈÝ $fp->next();// ÏÂÒ»ÐÐ } }else{//PHP<5.1 $fp = fopen($filename, $method); if(!$fp) return 'error:can not read file'; for ($i=1;$i<$startLine;++$i) {// Ìø¹ýÇ°$startLineÐÐ fgets($fp); } for($i;$i<=$endLine;++$i){ $content[]=fgets($fp);// ¶ÁÈ¡ÎļþÐÐÄÚÈÝ } fclose($fp); } return array_filter($content); // array_filter¹ýÂË£ºfalse,null,'' } $content = getFileLinesContent($file, $lines-10, $lines); print_r($content); ?>Ps:
ÉÏÃ涼û¼Ó"¶ÁÈ¡µ½Ä©Î²µÄÅжÏ"£º!$fp->eof() »òÕß !feof($fp)£¬¼ÓÉÏÕâ¸öÅжÏÓ°ÏìЧÂÊ£¬×Ô¼º¼ÓÉϲâÊԺܶàºÜ¶àºÜ¶àÐеÄÔËÐÐʱ¼ä¾ÍÏþµÃÁË£¬¶øÇÒÕâÀï¼ÓÉÏÒ²Íêȫû±ØÒª¡£
´ÓÉÏÃæµÄº¯Êý¾Í¿ÉÒÔ¿´³öÀ´Ê¹ÓÃSplFileObject±ÈÏÂÃæµÄfgetsÒª¿ì¶àÁË£¬ÌرðÊÇÎļþÐÐÊý·Ç³£¶à¡¢²¢ÇÒҪȡºóÃæµÄÄÚÈݵÄʱºò¡£fgetsÒªÁ½¸öÑ»·²Å¿ÉÒÔ£¬²¢ÇÒҪѻ·$endLine´Î¡£
´Ë·½·¨»¨Á˲»ÉÙ¹¦·ò£¬²âÊÔÁ˺ܶàÖÐд·¨£¬¾ÍÊÇÏëµÃ³öЧÂÊ×î¸ßµÄ·½·¨¡£ÄÄλ¾õµÃÓÐÖµµÃ¸Ä½øµÄ»¶Ó´Í½Ì¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ