使用 php 写入 Apache access_log 文件 [英] Writing to Apache access_log file with php

查看:33
本文介绍了使用 php 写入 Apache access_log 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将统计数据写入实时 Apache access_log 文件(我有另一个进程计算 access_log 文件中的特定行,该文件定期向另一个进程报告).

I need to write statistical data to the live Apache access_log file (I have another process counting specific lines in the access_log file that reports periodically back to another process).

目前我只是通过在 php 中执行以下操作来强制进入 access_log 文件:

Currently I am simply forcing an entry into the access_log file by doing the following in php:

file("http://127.0.0.1/logme.php?stuff_that_I_can_watch_here");

logme.php 不执行任何操作并返回 200 成功为空.

logme.php does nothing and returns empty with a 200 success.

上述技术的问题在于,对于对 Apache 服务器的每个请求,都会产生另一个请求写入日志 - 因此所需的 apache 服务器增加一倍.

The problem with the above technique is that for every request to the Apache server, another is spawned to write to the log - hence doubling required apache servers.

当服务器堆积起来时,对 Apache 服务器的简单且通常快速的本地调用需要 5 秒以上.

When the servers pile up, the simple and usually fast local call to the Apache server takes over 5 seconds.

我可以直接写入 access_log 文件而不引起问题吗,或者甚至有没有办法使用类似于 syslog() 或 error_log() 的 php 写入 apache_log 文件?

Can I write to the access_log file directly without causing problems, or maybe even is there a way to write to the apache_log file using php similar to syslog() or error_log()?

推荐答案

您可以使用 apache_note (http://php.net/apache_note) 将您的值写入注释,然后使用 CustomLogLogFormat (%{NOTE_NAME}n) (http://httpd.apache.org/docs/2.2/mod/mod_log_config.html) 以记录新密钥.解析访问日志的程序也可以读取新的日志参数.

You can use apache_note (http://php.net/apache_note) to write your values to a note and then use CustomLog with LogFormat (%{NOTE_NAME}n) (http://httpd.apache.org/docs/2.2/mod/mod_log_config.html) to log the new keys. Your programs which parse the access log can then read the new logging parameters as well.

这篇关于使用 php 写入 Apache access_log 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆