gpt4 book ai didi

performance - .htaccess mod_rewrite 性能

转载 作者:行者123 更新时间:2023-12-01 16:15:35 27 4
gpt4 key购买 nike

我在 SOF 上搜索了很多关于 .htaccess 和 mod_rewrite 的内容,我想知道哪一个更快:

RewriteRule ^([a-z0-9]+)/?$ index.php?id=$1 [NC,L]
RewriteRule ^(.*)/?$ index.php?id=$1 [NC,L]
RewriteRule ^([^/]*)/?$ index.php?id=$1 [NC,L]

由于第一个仅接受字母和数字,它是否会使执行速度更快?

最佳答案

如有疑问,请进行测试。我设置了一个运行 Ubuntu 2011.10 和 Apache2 的测试服务器,并使用 siege 负载测试应用程序执行了 3 项测试。测试运行 1 分钟(或直到 5000 次失败),有 50 个并发用户请求“/index.html”

测试 #1 使用以下重写规则配置:

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:

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:

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

关于performance - .htaccess mod_rewrite 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8145128/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com