Can PHP read server HTTP logs?

2019-08-23 09:00发布

I'd like to easily access the logs of a server to interpret them in a way and display that data to a website visitor. How can PHP access the HTTP logs of a server and all data therein?

标签: php logging
2条回答
何必那么认真
2楼-- · 2019-08-23 09:15

The server logs are generally just a file that you can read and parse as any other file. Reading it line by line and using split or a regular expression are commonly done.

These can get quite large, though, so it's not unusual to have a separate process that runs once a day or an hour or whatever that updates a summary file, which would then be read by your PHP script. Or often the separate process generates static HTML pages that then just get served. There are many log analyzers that work this way.

查看更多
相关推荐>>
3楼-- · 2019-08-23 09:31

Easiest way: create a symbolic link from /var/log/apache2/{acces,error,...}.log to a readable dir, e.g: /var/www

查看更多
登录 后发表回答