htaccess的mod_rewrite的性能 [英] .htaccess mod_rewrite performance
问题描述
我搜索了很多关于特种作战部队的.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和所使用的攻城负载测试的应用程序进行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]
从攻城结果:
The results from siege:
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屋!