.htaccess mod_rewrite 性能 [英] .htaccess mod_rewrite performance
问题描述
我在 SOF 上搜索了很多关于 .htaccess 和 mod_rewrite 的内容,我想知道哪个更快:
i searched a lot on SOF about .htaccess and mod_rewrite and i want to performance wise which one is faster:
RewriteRule ^([a-z0-9]+)/?$ index.php?id=$1 [NC,L]
RewriteRule ^(.*)/?$ index.php?id=$1 [NC,L]
RewriteRule ^([^/]*)/?$ index.php?id=$1 [NC,L]
因为第一个只接受字母和数字,所以执行起来会更快吗?
since the first one only accepts letters and numbers does it make it faster to execute?
推荐答案
如有疑问,请进行测试.我设置了一个运行 Ubuntu 2011.10 和 Apache2 的测试服务器,并使用 siege 负载测试应用程序执行 3 个测试.测试运行 1 分钟(或直到 5000 次失败),有 50 个并发用户请求/index.html"
When in doubt, test it out. I setup a test server running Ubuntu 2011.10 with Apache2 and used the siege load testing app to perform 3 tests. The test ran for 1 minute (or until 5000 failures) with 50 concurrent users requesting '/index.html'
测试 #1 使用了以下重写规则配置:
Test #1 used the following rewrite rule configuration:
RewriteEngine on
RewriteRule ^([a-z0-9]+)/?$ /index.html?id=$1 [NC,L]
围攻的结果:
Transactions: 300970 hits
Availability: 98.36 %
Elapsed time: 57.25 secs
Data transferred: 20.38 MB
Response time: 0.00 secs
Transaction rate: 5257.12 trans/sec
Throughput: 0.36 MB/sec
Concurrency: 9.04
Successful transactions: 300970
Failed transactions: 5009
Longest transaction: 0.02
Shortest transaction: 0.00
使用重写规则配置测试 #2:
Test #2 with a rewrite rule configuration:
RewriteEngine on
RewriteRule ^(.*)/?$ /index.html?id=$1 [NC,L]
结果:
Transactions: 225244 hits
Availability: 97.82 %
Elapsed time: 42.43 secs
Data transferred: 15.25 MB
Response time: 0.00 secs
Transaction rate: 5308.60 trans/sec
Throughput: 0.36 MB/sec
Concurrency: 8.71
Successful transactions: 225244
Failed transactions: 5009
Longest transaction: 0.18
Shortest transaction: 0.00
使用以下重写规则测试 #3:
Test #3 with the following rewrite rule:
RewriteEngine on
RewriteRule ^([^/]*)/?$ /index.html?id=$1 [NC,L]
结果:
Transactions: 210469 hits
Availability: 97.68 %
Elapsed time: 39.39 secs
Data transferred: 14.25 MB
Response time: 0.00 secs
Transaction rate: 5343.21 trans/sec
Throughput: 0.36 MB/sec
Concurrency: 8.60
Successful transactions: 210469
Failed transactions: 5009
Longest transaction: 0.02
Shortest transaction: 0.00
这篇关于.htaccess mod_rewrite 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!