您好,欢迎访问一九零五行业门户网

PHP 大日志文件读写

日志文件较大,2个多g。没办法用file操作,只能按行读取。
set_time_limit(0);@ini_set('memory_limit', '64m');$conn = mysql_pconnect('localhost', 'hcq', 'hcq') or die(con\'t connection db.);mysql_select_db('log', $conn);mysql_query('set names utf8', $conn);$file = '/home/hcq/data/www.nimmin.com_20120601_access.log';$handle = fopen($file, r) or die(can\'t open file {$file});while($log = stream_get_line($handle, 8192, \n)) {    $i = explode(' ', $log);    $path = isset($i[6]) ? str_replace('http://www.nimmin.com', '', $i[6]) : false;    if($path) { preg_match('/(jpg|png|gif)/iu', $path, $m); if(isset($i[8]) && $i[8] === '200' && count($m) > 0) { $len = isset($i[9]) ? intval($i[9]) : 0; $refer = isset($i[12]) ? str_replace('', '', $i[12]) : ''; mysql_query('insert into trace(path, len, refer) values (\''.$path.'\', '.$len.', \''.$refer.'\')', $conn); } }}fclose ($handle);exit;
复制代码
其它类似信息

推荐信息