I want analysis access_log, then store the visitors ip, date, pageview or image view into a mysql table.
I'm plan to use cron job call a php script every minute, open the access_log.
But now the access_log
has already more than 500MB, and it will increase about 0.4MB per minute. (usually 50-350 records)
so how to open such a big file in php? read last 500 records then regex get the last minute's records. My server has 32GB RAM, memory is no problem, but i need a lower cpu usage. Anyone can help me with a simple code? Thanks.
Edit
take advice by @Jeremiah Winsley, I use rotatelogs in my httpd.conf. But no log has been created. where is the problem?
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" com bined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined env=!dontlog
CustomLog "|sbin/rotatelogs -f logs/my_log 60" combined env=!dontlog
#create a my_log every 1 minute.
SetEnvIf Remote_Addr "127\.0\.0\.1" dontlog
SetEnvIf Remote_Addr "::1" dontlog
</IfModule>