Forum Moderators: phranque
[edited by: incrediBILL at 11:24 pm (utc) on Apr 19, 2013]
[edit reason] Edit for TOS #4 [/edit]
The difference is less than a millisecond. It's less than even a microsecond
^([^/]+/)*foo\.html$ ^(.*/)?foo\.html$ $nRequests = 100;
$start = microtime(true);
for ($i = 0; $i < $nRequests; $i++) {
file_get_contents('http://localhost/foo.html');
}
$stop = microtime(true);
$totalTime = $stop - $start;
$averageTimePerRequest = $totalTime / $nRequests;
$averageTimePerRequestInMicroseconds = $averageTimePerRequest * 1000;
echo "$averageTimePerRequestInMicroseconds microseconds"; siege -c25 -t1M http://localhost/foo.html). The first pattern averaged 32.87 requests per second. The second pattern averaged 33.02 requests per second. Interestingly, in this test, the second pattern performed better. http://localhost/foo.html
^(.*)/(.*)/page-(.*).html$
[edited by: incrediBILL at 4:07 am (utc) on Apr 21, 2013]
[edit reason] TOS #4 - DISCUSS THE TOPIC - NOT THE MEMBERS [/edit]
^.*something.*$ something [edited by: Dideved at 8:24 am (utc) on May 4, 2013]
introduce a bug
I don't understand what you're trying to say here.
the prevailing wisdom of the web community
(d) the expression .* should never be used in mid-pattern if you can possibly help it. If you can't get by with a simple
%{THE_REQUEST} index\.html
then use
/([^/]+/)*index\.html
[edited by: phranque at 12:04 pm (utc) on Jun 30, 2013]
[edit reason] clarify System tracks [/edit]
Some years ago, jdMorgan showed that for server under high load, these things did make a difference.
The fact that .* is "greedy, promiscuous and ambiguous"...
I'll repeat again. When designing a RegEx pattern, aim to have it parse cleanly from left to right in a single pass without any back-tracking.
That's not a fact.
It is a fact. The words "greedy", "promiscuous" and "ambiguous" are all technical terms with precise meanings.
Lots of people get by with imperfect rules and slapdash patterns. It is much less common for someone to actively encourage and recommend doing things sloppily-- not simply because you're lazy and "it's good enough for me" but because you think it's better to do a half-### job.