Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Recursion limitations in PHP?

  1. #1
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default Recursion limitations in PHP?

    I'm working on a project for an engineering course with extreme number crunching (this will take hours to run, at a minimum, and that's just one iteration).

    I am having trouble writing the code, and I keep writing infinite loops. PHP gives up and throws an error (I've tried a couple servers and the error varies but the behavior is the same-- it gives up).

    But now I'm not so sure I'm writing an infinite loop. It's a huge amount of number crunching (something like 17,000^2) and it's giving up. I'd assume I'm writing an infinite loop somewhere but I can't find it. (This code is incredibly frustrating in the first place, so I might be missing it.)

    So my questions...
    1. How does PHP know when there is an infinite loop without trying it out? How does it know when to give up? It's not a delayed response-- it instantaneously gives up as soon as it gets the request. (And it's not a parse error. I can comment out the recursion and it goes on just fine.)

    2. Is this something I can configure? I hesitate to turn it off, but I have a feeling I might have hit the limits of PHP's calculating capabilities.



    (And I know PHP is not the ideal language for this; it's just the one I'm most familiar with and this project is a pain, perhaps excessive. Homework! Yay!)



    (If anyone is wondering what I'm working on, it's using a Hidden Markov Model to calculate distributional frequencies/probabilities of sounds [=letters] in an input string of language and attempting to uncover "hidden structure". A bit of statistical magic, basically, and I don't fully understand it.)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Hm. phpinfo() gives this info: pcre.recursion_limit: 100000
    According to what I've found with search results, that may be responsible for recursion limitations. But that's kind of riciculous, and I don't think it's actually meant to get to 100,000 levels deep with this code. But it might be. I guess I'll keep playing with it.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    Could it be your php.ini value for set_time_limit has been exceeded?

    See more here: http://php.net/manual/en/function.set-time-limit.php
    To choose the lesser of two evils is still to choose evil. My personal site

  4. The Following User Says Thank You to james438 For This Useful Post:

    djr33 (03-25-2013)

  5. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    That's the weird thing-- I'm running into two kinds of problems: 1) sometimes it times out; 2) sometimes it refuses to run due to recursion. So (2) is definitely not related to time, because it immediately gives up-- on one server it gives a 500 error; on the other it seems to silently stop at the recursion.


    (Unrelated to the problem at hand, I will have to do something about the time limit; in the past I've gotten around it by doing a little bit each time the page runs then reloading the page [automatically, with a redirect]. Or I could just turn that off. In the end I'll probably be only running this locally so as to not anger my host.)
    Last edited by djr33; 03-25-2013 at 05:47 AM.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    Is there an error message? PHP is also needs processing power to run, so it could be the processing power of the servers is not the best although I'm not sure how to go about testing this.

    I just realized that you indicated you are using pcre. With calculations like what you are doing I would recommend outsourcing to Perl. PCRE is extremely processor heavy last I heard and I have not heard any word on that no longer being the case.
    To choose the lesser of two evils is still to choose evil. My personal site

  7. The Following User Says Thank You to james438 For This Useful Post:

    djr33 (03-25-2013)

  8. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Oops. I meant 500 error in my post above-- a configuration error.

    Is there an error message? PHP is also needs processing power to run, so it could be the processing power of the servers is not the best although I'm not sure how to go about testing this.
    Hm. It seems to be giving up before this could be a problem.

    I just realized that you indicated you are using pcre. With calculations like what you are doing I would recommend outsourcing to Perl. PCRE is extremely processor heavy last I heard and I have not heard any word on that no longer being the case.
    I wouldn't know where to start there, but it would be fine with me to configure it differently. I'm not sure how well that would work on my localhost configuration though-- just the default OSX PHP installation.


    I'm not intentionally using PCRE, but I'm not sure how to avoid it either.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #7
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,689
    Thanks
    82
    Thanked 89 Times in 87 Posts

    Default

    Is Perl enabled on your hosting configuration? Do you use deluxe or higher with your GoDaddy account? This would indicate whether it is even possible to use Perl.

    The best regular expression experts can be found here: http://regexadvice.com/forums/default.aspx It is not the most advanced website and they are rather strict about posting guidelines, but these people do nothing but regular expressions using all programming languages and not just web design either.
    To choose the lesser of two evils is still to choose evil. My personal site

  10. The Following User Says Thank You to james438 For This Useful Post:

    djr33 (03-25-2013)

  11. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Is Perl enabled on your hosting configuration? Do you use deluxe or higher with your GoDaddy account? This would indicate whether it is even possible to use Perl.
    I'll probably be running this on my localhost (macbook) because it'll be running for several hours straight.

    The best regular expression experts can be found here: http://regexadvice.com/forums/default.aspx It is not the most advanced website and they are rather strict about posting guidelines, but these people do nothing but regular expressions using all programming languages and not just web design either.
    I'm not using regex actually. This is all 'for' loops in PHP doing math based on input text. Maybe PCRE only has that limit imposed for regex? If so, that isn't my problem at all. (But it's the only mention of "recursion" in phpinfo().)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  12. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    For the record, I've got it working now. I'm not sure what was going wrong before (I'm a bit lost in this code at the moment), but I'll keep playing with it. It's good to check on these things.

    Since I use PHP so much for web design, I occasionally use it for other things too and then I run into these odd performance issues when I'm doing something beyond what it's designed for. But usually, with a bit of experimentation, it works.




    It *might* have just been a typo in the direction of the loop (subtracting instead of adding; slightly less obvious than that in how I had written it though), but I'm not sure. Working for now.
    I also need to remember to not have it output data as it loops-- that seems to slow things down a lot. It was taking about 30 seconds to load the page, but now it's down to 3 when I'm just calculating a value. [And there will be many iterations of this, but that's the base loop at least.]
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  13. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,920
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    As a side note here, just as in any other language which has both, the while loop is more efficient than the for loop. The more iterations of the loop, the more of an efficiency while represents over for.

    Also, when incrementing or decrementing a variable:

    ++$var;

    and:

    --$var;

    are more efficient than:

    $var++

    and:

    $var--

    Again, the more iterations, the more efficient.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  14. The Following User Says Thank You to jscheuer1 For This Useful Post:

    djr33 (03-25-2013)

Similar Threads

  1. textarea limitations
    By lord22 in forum JavaScript
    Replies: 2
    Last Post: 11-09-2009, 02:06 PM
  2. Limitations of Pausing RSS scroller
    By troyboy in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-15-2007, 07:20 PM
  3. AJAX Cross-Domain Limitations
    By Twey in forum JavaScript
    Replies: 1
    Last Post: 10-01-2006, 05:01 PM
  4. what are PHP mail limitations
    By kusalo in forum PHP
    Replies: 4
    Last Post: 09-13-2006, 01:34 PM
  5. ajaxcontent: security limitations override possible?
    By Grobbo in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 03-20-2006, 07:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •