eric1235711 Posted April 7, 2006 Share Posted April 7, 2006 Hello,I´m doing some tests...and look this one:[code]<?phpclass Test{ var $vari; var $subclass; // constructor function Test($qt){ $this->vari = "$qt"; echo $qt.' '; $qt ++; $this->subclass = new Test($qt); }}$qt = 0;$objeto = new Teste($qt);?>[/code]Here it ran 872 levels and php just stopped, returning no errors... do you know what happened?I just ran this one:[code]function test2($qt){ echo "$qt "; flush(); if($qtd < 10000) return test2(++$qtd); else return 'end';}echo test2(0);[/code]and the error was the same: 872 levels of recursion and no error message...I´m asking this because I'm going to do a work that uses recursion. Do you find that it´s better to use another language?Don´t you find that php should run them while execution time limit haven´t been reached? Quote Link to comment https://forums.phpfreaks.com/topic/6800-endless-recurtion/ Share on other sites More sharing options...
lead2gold Posted April 7, 2006 Share Posted April 7, 2006 [!--quoteo(post=362496:date=Apr 7 2006, 08:47 AM:name=eric1235711)--][div class=\'quotetop\']QUOTE(eric1235711 @ Apr 7 2006, 08:47 AM) [snapback]362496[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hello,I´m doing some tests...and look this one:[code]<?phpclass Test{ var $vari; var $subclass; // constructor function Test($qt){ $this->vari = "$qt"; echo $qt.' '; $qt ++; $this->subclass = new Test($qt); }}$qt = 0;$objeto = new Teste($qt);?>[/code]and the error was the same: 872 levels of recursion and no error message...I´m asking this because I'm going to do a work that uses recursion. Do you find that it´s better to use another language?Don´t you find that php should run them while execution time limit haven´t been reached?[/quote]The problem is "Test" is the class. A function within "Test" called "Test" is now the constructor.If the constructor creates another class of (itself) like you do. It recursivly keeps calling itself again and again.[code]<?phpclass Test{ var $vari; var $subclass; // constructor function Test($qt){ // constructor (remember, GenSubClass will call this too (in it's own memory space) $subclass = NULL; // initialize $this->vari = "$qt"; echo $qt.' '; $qt ++; } function GenSubClass(){ // break into it's own function if(!$subclass)$this->subclass = new Test($this->vari); }}$qt = 0;$objeto = new Teste($qt);$objeto->GenSubclass(); // make call seperatly to avoid recurision?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6800-endless-recurtion/#findComment-24733 Share on other sites More sharing options...
eric1235711 Posted April 7, 2006 Author Share Posted April 7, 2006 I´m testing the capacity of php with recursive functions and objects...I made them endless to know the limits.My doubts are:1. 872 levels is the limit of php or of my memory? 2. Is there any settings to increase this number of levels?3. Is there any settings to "recurse" til execution time limit is reached? Quote Link to comment https://forums.phpfreaks.com/topic/6800-endless-recurtion/#findComment-24796 Share on other sites More sharing options...
lead2gold Posted April 7, 2006 Share Posted April 7, 2006 I'm sorry for overlooking your question.php is a "loadmodule" command in Apache as you know. Thus it's a pre-compiled library. Whatever amount of memory Apache alots for each module is most likely set in the compiler at runtime (when compiling Apache).Apache is open source however... i'm sure you could adjust this and recompile the code (i don't know if that would break any EULA though).I'm not sure what the limit restrictions on Apache... but keep in mind that each connection Apache recieves to it causes it to spawn a seperate thead. The memory allocated to each thread has to be governed in such a crash that your trying to produce. In cases like yours, the thread needs to shutdown gracefully and deliver an error message to the end user.You definatly did a great test to find out what the limit is set at... but i don't think your going to find an easy way of altering that without tampering with the stability of Apache.Edit: to answer your questions from what i wrote:1. 872 levels is the limit of php or of my memory? A: limit of Apache (or whatever server you are using)2. Is there any settings to increase this number of levels?A: edit apache source code3. Is there any settings to "recurse" til execution time limit is reached?A: I don't know, maybe someone else can reply to this thread and add to this question. Quote Link to comment https://forums.phpfreaks.com/topic/6800-endless-recurtion/#findComment-24819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.