Htaccess:触发php或写入日志

时间:2022-05-26 11:17:45

I want a redirect which is as fast as possible. So I decided to use htaccess redirect , because it responses even before the php interpreter is initialized. But I want to log the redirects and write something to the Database.

我想要一个尽可能快的重定向。所以我决定使用htaccess重定向,因为它甚至在php解释器初始化之前就会响应。但我想记录重定向并向数据库写入内容。

I tried to redirect and call rewritemap just to trigger a php file but, it only throws a 500 error.

我试图重定向并调用rewritemap只是为了触发一个php文件,但它只会抛出500错误。

I would be ok, if i can create a log file, even if the log processing would be delayed. Important is only: Fast redirect, track / log a redirect.

我没关系,如果我可以创建一个日志文件,即使日志处理会被延迟。重要的是:快速重定向,跟踪/记录重定向。

Have you got any ideas or recommendations on this?

你对此有什么想法或建议吗?

thank you in upfront

先谢谢你

all the best,

祝一切顺利,

emre

4 个解决方案

#1


2  

You could use RewriteLog to log rewriting actions to a file -- that would be done by Apache, without invoking PHP.

您可以使用RewriteLog将重写操作记录到文件中 - 这可以由Apache完成,而无需调用PHP。

=> Quite fast ; but logs only to a file, not a database ; still, as you said, the log processing can be delayed, and done by a script run from the crontab.

=>相当快;但只记录到文件,而不是数据库;仍然如你所说,日志处理可以延迟,并通过从crontab运行的脚本完成。


See also RewriteLogLevel, to configure how verbose that log should be.

另请参阅RewriteLogLevel,以配置该日志的详细程度。

#2


1  

Can be used in apache/vhost config, but not in .htaccess (so if you can put it there, remember to reload apache):

可以在apache / vhost配置中使用,但不能在.htaccess中使用(所以如果你可以把它放在那里,记得重新加载apache):

    RewriteEngine On
    RewriteRule /foo http://www.example.com [R=301,E=redirected]

    CustomLog /path/to/log combined env=redirected

'combined' is a default log format, but you can define your own

'combined'是默认的日志格式,但您可以定义自己的格式

#3


1  

If your goal is simply fast as possible with logging, then the primary point of concern is keeping disk I/O to a minimum. Relying on .htaccess, you're doing a directory scan at each level of the URL (http://muffinresearch.co.uk/archives/2008/04/07/avoiding-the-use-of-htaccess-for-performance/).

如果您的目标在记录时尽可能快,那么主要关注点是将磁盘I / O保持在最低限度。依靠.htaccess,您在URL的每个级别进行目录扫描(http://muffinresearch.co.uk/archives/2008/04/07/avoiding-the-use-of-htaccess-for-performance /)。

If you could setup your RewriteRule in Apache's conf, and point your redirects to a PHP file, then you could have PHP running w/ APC and have the logging done to a memcache object. That way your entire client's access could occur purely in fast-access memory, and you could have a cron-job that'd routinely take the data from memcache and push it to the database (this way you'd still have long-term storage but the client's access should never require the disk to be read.)

如果您可以在Apache的conf中设置RewriteRule,并将重定向指向PHP文件,那么您可以让PHP运行w / APC并将记录完成到memcache对象。这样你的整个客户端的访问可以完全发生在快速访问内存中,你可以有一个cron-job,它会定期从memcache中获取数据并将其推送到数据库(这样你仍然可以长期存储但是客户端的访问权限永远不应该要求读取磁盘。)

Obviously if you're flexible on the database, you could use a Couchbase-style solution that'd essentially let you have speed of writing to memcache without storing the information in volatile memory, but I'm guessing you're locked into the database you're currently using.

显然,如果你对数据库很灵活,你可以使用Couchbase风格的解决方案,它基本上让你有速度写入memcache而不将信息存储在易失性存储器中,但我猜你已被锁定在数据库中你现在正在使用。

#4


0  

You might want t try an apache log to mysql module like: http://www.outoforder.cc/projects/apache/mod_log_sql/ here is a howto for debian http://www.howtoforge.com/apache2-logging-to-a-mysql-database-with-mod_log_sql-on-debian-etch

你可能想要尝试一个apache日志到mysql模块,如:http://www.outoforder.cc/projects/apache/mod_log_sql/这里是debian的一个howto http://www.howtoforge.com/apache2-logging-to -a MySQL的数据库与 - mod_log_sql-ON-Debian的蚀刻

However I'm not 100% sure this works with the latest apache.

但是我并不是100%肯定这适用于最新的apache。

Good Luck

#1


2  

You could use RewriteLog to log rewriting actions to a file -- that would be done by Apache, without invoking PHP.

您可以使用RewriteLog将重写操作记录到文件中 - 这可以由Apache完成,而无需调用PHP。

=> Quite fast ; but logs only to a file, not a database ; still, as you said, the log processing can be delayed, and done by a script run from the crontab.

=>相当快;但只记录到文件,而不是数据库;仍然如你所说,日志处理可以延迟,并通过从crontab运行的脚本完成。


See also RewriteLogLevel, to configure how verbose that log should be.

另请参阅RewriteLogLevel,以配置该日志的详细程度。

#2


1  

Can be used in apache/vhost config, but not in .htaccess (so if you can put it there, remember to reload apache):

可以在apache / vhost配置中使用,但不能在.htaccess中使用(所以如果你可以把它放在那里,记得重新加载apache):

    RewriteEngine On
    RewriteRule /foo http://www.example.com [R=301,E=redirected]

    CustomLog /path/to/log combined env=redirected

'combined' is a default log format, but you can define your own

'combined'是默认的日志格式,但您可以定义自己的格式

#3


1  

If your goal is simply fast as possible with logging, then the primary point of concern is keeping disk I/O to a minimum. Relying on .htaccess, you're doing a directory scan at each level of the URL (http://muffinresearch.co.uk/archives/2008/04/07/avoiding-the-use-of-htaccess-for-performance/).

如果您的目标在记录时尽可能快,那么主要关注点是将磁盘I / O保持在最低限度。依靠.htaccess,您在URL的每个级别进行目录扫描(http://muffinresearch.co.uk/archives/2008/04/07/avoiding-the-use-of-htaccess-for-performance /)。

If you could setup your RewriteRule in Apache's conf, and point your redirects to a PHP file, then you could have PHP running w/ APC and have the logging done to a memcache object. That way your entire client's access could occur purely in fast-access memory, and you could have a cron-job that'd routinely take the data from memcache and push it to the database (this way you'd still have long-term storage but the client's access should never require the disk to be read.)

如果您可以在Apache的conf中设置RewriteRule,并将重定向指向PHP文件,那么您可以让PHP运行w / APC并将记录完成到memcache对象。这样你的整个客户端的访问可以完全发生在快速访问内存中,你可以有一个cron-job,它会定期从memcache中获取数据并将其推送到数据库(这样你仍然可以长期存储但是客户端的访问权限永远不应该要求读取磁盘。)

Obviously if you're flexible on the database, you could use a Couchbase-style solution that'd essentially let you have speed of writing to memcache without storing the information in volatile memory, but I'm guessing you're locked into the database you're currently using.

显然,如果你对数据库很灵活,你可以使用Couchbase风格的解决方案,它基本上让你有速度写入memcache而不将信息存储在易失性存储器中,但我猜你已被锁定在数据库中你现在正在使用。

#4


0  

You might want t try an apache log to mysql module like: http://www.outoforder.cc/projects/apache/mod_log_sql/ here is a howto for debian http://www.howtoforge.com/apache2-logging-to-a-mysql-database-with-mod_log_sql-on-debian-etch

你可能想要尝试一个apache日志到mysql模块,如:http://www.outoforder.cc/projects/apache/mod_log_sql/这里是debian的一个howto http://www.howtoforge.com/apache2-logging-to -a MySQL的数据库与 - mod_log_sql-ON-Debian的蚀刻

However I'm not 100% sure this works with the latest apache.

但是我并不是100%肯定这适用于最新的apache。

Good Luck