0

Is there some kind of PHP configuration setting that would affect the length of string being passed into preg_match or preg_match_all?

I have the following which I am trying to test to work out what is going wrong for me:

    $re = "/\[\[section\:(.*?)\]\]((.|\n)*?)\[\[endsection\]\]/"; 
    $str = "[[section:body]]
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    lots of lines here
    [[endsection]]

    other stuff here"; 

    preg_match_all($re, $str, $matches);
    var_dump($matches);

Now if I run that it's fine, it returns the results pretty much instantly.

But if I add one more line to the $str variable and run it again, it just spins and spins and then I get web page cannot be displayed.

But if I then run that exact same thing on writecodeonline.com/php it works fine and returns instantly.

I'm not getting any errors in my php error log or my apache error logs, it just refuses to do anything once it hits that certain characters (it seems to be that as soon as it hits 707 characters it stops responding.

Has anyone come across this sort of issue before? Is it just some configuration setting I need to change?

Cheers.

CMR
  • 1,366
  • 4
  • 15
  • 31
  • To add onto this, that php.ini setting suggested below hasn't helped. The same issue is still occuring. I've tried doing a webgrind profile of the script to see what is happening, but as soon as it hits the 695 characters in the string, it doesn't even create a profile output, it's empty, and the script just does nothing except sit there spinning for about 20 seconds or so. Yet remove one character from the string and the result is instant. – CMR Mar 14 '15 at 14:34
  • This seems to be the exact same issue: http://forum.wampserver.com/read.php?2,65936,65946 I am on WAMP server as well, and my issue is behaving exactly the same as that persons – CMR Mar 14 '15 at 14:51
  • 1
    Resolved this using info from: http://stackoverflow.com/questions/7620910/regexp-in-preg-match-function-returning-browser-error Basically the default setting of 100000 for pcre.recursion_limit was too high, causing (i think) a stack overflow, which crashed apache and caused it to restart, which explains my no errors in my apache error log, but restart notifications. I changed it to 524 for my WAMP installation, as per instructions in that question. – CMR Mar 14 '15 at 15:18

1 Answers1

0

Yes, there is the backtrack-limit

You can configure this in your php.ini file.

To be honest, a quick google search would have solved your problem...

sgtdck
  • 1,008
  • 7
  • 15
  • I've made sure that that setting is set to 100000 in the php.ini, but the same issue is still occuring. – CMR Mar 14 '15 at 14:20
  • Now it seems to be as soon as it hits 695 characters it stops working. – CMR Mar 14 '15 at 14:26
  • I have resolved this now, using the information found in this question: http://stackoverflow.com/questions/7620910/regexp-in-preg-match-function-returning-browser-error – CMR Mar 14 '15 at 15:11
  • @ConnWarwicker can you elaborate a bit more on what information in that question helped you solve it? Might be a good reference for people encountering this in the future. Thanks. – sgtdck Mar 14 '15 at 15:12
  • 1
    I have added that as a comment to my question. – CMR Mar 14 '15 at 15:18