简体   繁体   English

PHP CURL导致巨大的Apache访问日志

[英]PHP CURL causing Huge Apache access log

I'm curious to know how to stop Apache from logging every URL I search with CURL. 我很好奇知道如何阻止Apache记录我使用CURL搜索的每个URL。

My PHP script opens a few hundred thousand URLs, scans them, takes a tiny bit of info, closes, and then opens the next. 我的PHP脚本打开了数十万个URL,对其进行扫描,只需要一点信息,然后关闭,然后打开下一个。

I discovered after opening the access log that each and every URL opened with CURL is written to the access log. 在打开访问日志后,我发现用CURL打开的每个URL均被写入访问日志。

::1 - - [01/Dec/2010:18:37:37 -0600] "GET /test.php HTTP/1.1" 200 8469 "-"..."

My access log is almost 45MBytes large. 我的访问日志几乎是45 MB。 Help anyone? 帮助任何人?

This is the purpose for access log - recording any incoming traffic 这是访问日志的目的-记录所有传入流量

In order to effectively manage a web server, it is necessary to get feedback about the activity and performance of the server as well as any problems that may be occurring. 为了有效地管理Web服务器,有必要获取有关服务器活动和性能以及可能发生的任何问题的反馈。 The Apache HTTP Server provides very comprehensive and flexible logging capabilities. Apache HTTP Server提供了非常全面和灵活的日志记录功能。 This document describes how to configure its logging capabilities, and how to understand what the logs contain. 本文档介绍了如何配置其日志记录功能以及如何理解日志包含的内容。

source: http://httpd.apache.org/docs/trunk/logs.html 来源: http : //httpd.apache.org/docs/trunk/logs.html

Of course, you have the option to disable logging (preferable not) 当然,您可以选择禁用日志记录(最好不要)

See the Apache manual , about Conditional Logs . 请参阅Apache手册 ,了解条件日志 That may be what you are looking for. 那可能就是您想要的。

If all of your curl requests are coming from a single or otherwise manageable group of IPs you can exclude them from your logs with a configuration similar to the following: 如果所有卷曲请求都来自单个或其他可管理的IP组,则可以使用类似于以下的配置将它们从日志中排除:

# Set your address here, you can do this for multiple addresses
SetEnvIf Remote_Addr "1\.1\.1\.1" mycurlrequest
CustomLog logs/access_log common env=!mycurlrequest

You can do something similar with the user agent field which by default will indicate that it's curl. 您可以对User Agent字段执行类似的操作,默认情况下它将指示其卷曲。

You can read more here: http://httpd.apache.org/docs/2.2/logs.html#accesslog (conditional logging is the last section under this header) and here http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html#setenvif 您可以在此处了解更多信息: http : //httpd.apache.org/docs/2.2/logs.html#accesslog (条件日志记录是此标题下的最后一部分),以及http://httpd.apache.org/docs/ 2.2 / mod / mod_setenvif.html#setenvif

If you want to conditionally exclude logging I would to it by the most precise method possible such as the ip address. 如果您想有条件地排除日志记录,我会通过最精确的方法(例如ip地址)来登录。 In the event the server is externally accessible you probably don't want to find yourself NOT logging external requests from curl. 如果服务器可以从外部访问,则您可能不想让自己不记录curl的外部请求。

Using conditional logging you can also segment your logging if you want to multiple files one of which you could roll more frequently. 如果您要分割多个文件,则可以使用条件日志记录对日志进行分段,其中一个文件可以更频繁地滚动。 The benefit of that is you can save space and at the same time have log data to help research and debug. 这样做的好处是可以节省空间,同时拥有日志数据以帮助研究和调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM