Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

.htaccess mod_rewrite performance

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'

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

Test #2 with a rewrite rule configuration:

RewriteEngine on
RewriteRule ^(.*)/?$ /index.html?id=$1 [NC,L]

The results:

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

Test #3 with the following rewrite rule:

RewriteEngine on
RewriteRule ^([^/]*)/?$ /index.html?id=$1 [NC,L]

The results:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...