PHP preg_match_all limit

Ahmad picture Ahmad · Nov 25, 2011 · Viewed 11.6k times · Source

I'm using preg_match_all for very long pattern.

when run the code, i got this error :

Warning: preg_match_all(): Compilation failed: regular expression is too large at offset 707830

After searching, I got the solution, so I should increase value of pcre.backtrack_limit and pcre.recursion_limit in php.ini

But after I increase the value and restart my apache, it still got the same problem. My PHP verison is 5.3.8

Answer

Alan Moore picture Alan Moore · Nov 25, 2011

That error is not about the performance of the regex, it's about the regex itself. Changing the pcre.backtrack_limit and pcre.recursion_limit isn't going to have any effect because the regex never gets a chance to run. The problem is that the regex is too big, and the solution is to make the regex smaller--much, much smaller.