se1zure Posted March 1, 2007 Share Posted March 1, 2007 I wrote a program where the user enters a number, and then it finds all the factors of that number, and displays it in a table. It works great for the most part. Up to numbers like 99,999,999, but then problems arise. Adding another 9 to that (which then runs the loop 900 million more times) gives me this error: Fatal error: Maximum execution time of 60 seconds exceeded in /home2/data/hosted/scetchbook/php/factor.php on line 10 Is there a way to turn off the execution time limit? I though that, since theoretically, it doesn't need to test every number past half of the original (because 2 is the second lowest factor you won't always have), so it only needs to run the loop half of the times. I will do this, but is there a way to turn off the execution time limit. Here is the code for the program: <?php // FactorFinder v1 $num = $_POST["num"]; ; $goto = 1; echo "<p align='center'>Factors of $num:</br >"; echo "<table width='600' cellpadding='2' cellspacing='2' bgcolor='white'>"; echo "<tr><td width='200' align='center' bgcolor='#B0E2FF'><b> Factor </td><td bgcolor='#8DB6CD' width='200' align='center'><b><font color='white'> Multiplyer </td><td width='200' align='center' bgcolor='#B0E2FF'><b> Resultant </td></tr>"; $prime = 0; while ($goto <= $num){ $fac = $num%$goto; if ($fac==0){ $mult = $num / $goto; echo "<tr><td width='200' align='center' bgcolor='#8DB6CD'> <font color='white'>$goto </td><td bgcolor='#B0E2FF' width='200' align='center'> $mult </td><td width='200' align='center' bgcolor='#8DB6CD'> <font color='white'>$num </td></tr>"; $prime = $prime + 1; } else { echo ""; } $goto = $goto + 1; } echo "</table>"; if ($prime==2){ echo "This is a prime Number. It is divisible by only 1 and itself.";} else { echo "This is not a prime number, there are a total of $prime factors.";} ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/40634-solved-factorfinder-program-problem/ Share on other sites More sharing options...
pocobueno1388 Posted March 1, 2007 Share Posted March 1, 2007 You need to reset your max execution time in your php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/40634-solved-factorfinder-program-problem/#findComment-196527 Share on other sites More sharing options...
se1zure Posted March 1, 2007 Author Share Posted March 1, 2007 If i am hosting this online, how woudl I go about doing this? Thanks. Oh, and the reason I'm interested is, I want to create a loops that I'll leave running for a few months on my other computer to find as high of a prime number as a can (and potentially break the current record). Of course, I will run this from that computer, and not the net... but not for now. Quote Link to comment https://forums.phpfreaks.com/topic/40634-solved-factorfinder-program-problem/#findComment-196530 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 You can try this (as long as the server is not set for safe mode): http://sg.php.net/manual/en/function.set-time-limit.php Quote Link to comment https://forums.phpfreaks.com/topic/40634-solved-factorfinder-program-problem/#findComment-196586 Share on other sites More sharing options...
pocobueno1388 Posted March 1, 2007 Share Posted March 1, 2007 To be honest, I have no idea how to set the max executiong time in the php.ini file. I have just been coming and reading these forums so much that I have seen numerous topics such as this and it was solved that way, haha. EDIT: Oops, I didn't realize this topic was solved, sorry for bumping it. Quote Link to comment https://forums.phpfreaks.com/topic/40634-solved-factorfinder-program-problem/#findComment-196767 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.