The log file is large, more than 2G. There is no way to use file operation, only read line by line.
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;
-
-
- Copy code
-
|