ballhogjoni Posted August 22, 2008 Share Posted August 22, 2008 Fatal error: Maximum execution time of 30 seconds exceeded in /home/xxx/public_html/xxx/Home/home.php on line 82 What just happened, this use to work fine. I deleted stuff from the database but it shouldn't affect this code. Line 82 is commented below: <?php $rArticle = $db->Select('Articles','*','WHERE display_on_home_page = 1 LIMIT 1'); while ( $row = mysql_fetch_array( $rArticle ) ) { if( !empty( $row['article_id'] ) ){ $sTitle = $row['title']; $sTinyMCEData = $row['tinymcedata']; }else{ exit; } } $iMaxCharacters = 300; if( !empty( $sTinyMCEData ) ){ $sArticle = $sTinyMCEData; $sDisplayArticle = substr( $sArticle,$iMaxCharacters,1 ); if( $sDisplayArticle != " " ){ $i=1; while( $sDisplayArticle != " " ){ $iMaxCharacters = $iMaxCharacters+$i; //line 82 $sArticle = $sTinyMCEData; $sDisplayArticle = substr( $sArticle,$iMaxCharacters,1 ); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/ Share on other sites More sharing options...
btherl Posted August 22, 2008 Share Posted August 22, 2008 if( $sDisplayArticle != " " ){ $i=1; while( $sDisplayArticle != " " ){ $iMaxCharacters = $iMaxCharacters+$i; //line 82 $sArticle = $sTinyMCEData; $sDisplayArticle = substr( $sArticle,$iMaxCharacters,1 ); } } Is it possible that $sDisplayArticle never becomes equal to " " ? Try temporarily replacing this loop with a debug statement that prints out each $sDisplayArticle so you can verify that the values are what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622733 Share on other sites More sharing options...
btherl Posted August 22, 2008 Share Posted August 22, 2008 Sorry I forgot to explain - the reason it times out is that your script runs "forever". So I suspect that your loop there never terminates, and just keeps on looping until the 30 second limit kills it. Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622735 Share on other sites More sharing options...
maliary Posted August 22, 2008 Share Posted August 22, 2008 At certain times the error is brought about by an inadequate server. It takes too long to process and retrieve a query hence the error showing up. Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622747 Share on other sites More sharing options...
Zane Posted August 22, 2008 Share Posted August 22, 2008 you're not incrementing your $i variable $i=1; while( $sDisplayArticle != " " ){ $iMaxCharacters = $iMaxCharacters+$i; //line 82 $sArticle = $sTinyMCEData; $sDisplayArticle = substr( $sArticle,$iMaxCharacters,1 ); $i++ // } and you can just as easily increment iMaxCharacters like this too $iMaxCharacters++; you don't even need the $i variable Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622754 Share on other sites More sharing options...
JasonLewis Posted August 22, 2008 Share Posted August 22, 2008 Incrementing it by $i means it would increment by 1, then 2, then 3 etc etc. So $iMaxCharacters, for example, starts at 0. After the first loop, it's 1. After the second loop, it's 3. After the third it would be 6 and so on. Right? I guess that's probably what you want then. Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622756 Share on other sites More sharing options...
Zane Posted August 22, 2008 Share Posted August 22, 2008 No, that's called squaring Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622761 Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 No, that's called squaring hate to jump in here, but projectfear is right. in the first iteration, $i = 1, so $iMaxCharacters would be 1. next iteration, $i is 2, so $iMaxCharacters = 1+2 = 3. and so on. if one was squaring, there would be a common multiple between every member of the series (the base). Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622775 Share on other sites More sharing options...
Zane Posted August 22, 2008 Share Posted August 22, 2008 wow.....completely my bad on that one didn't even look that over. good thing I'm not getting paid sorry projectfear Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622777 Share on other sites More sharing options...
JasonLewis Posted August 22, 2008 Share Posted August 22, 2008 No dramas. Is that what the OP was after though. Kind of strange to be doing it like that. Oh well. Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622793 Share on other sites More sharing options...
Zane Posted August 22, 2008 Share Posted August 22, 2008 Not used to seeing an $i=1 and no counter involved, caught me off guard.......he's apparently using the $i variable to hold 1 which is useless which is why I suggested imaxcharacters++ in the first place.. well, it's back to square one on this one. need some more information i guess Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622803 Share on other sites More sharing options...
ballhogjoni Posted August 22, 2008 Author Share Posted August 22, 2008 I guess I should explain what the fucntion does...It query's the db for an article and only display 300 characters of that article. Now let me explain the loop in question. It searches for the first instance of " " ( a space ) after the 300 character max. The loop is so that if a word falls under and over the 300 character max it will search for the space after that word and end. This way I am not cutting off the last word. Therefore I need the $i to stay constant at 1 because it just adds one each time it loops. I know I could just do ++ at the end of imaxcharacters and probably will make that change. Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-622992 Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 what about strpos()? no use reinventing the wheel. Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-623048 Share on other sites More sharing options...
btherl Posted August 25, 2008 Share Posted August 25, 2008 This will give you the offset of the first space following the 300th character: $offset = strpos($string, ' ', 300); If there are no spaces then this will result in "false", so you must check for that value. If it's not false, then you can use that number in substr() Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-624729 Share on other sites More sharing options...
cooldude832 Posted August 25, 2008 Share Posted August 25, 2008 even better why not use mysql to get the substr out of that database for you? Less garbage out is always better Quote Link to comment https://forums.phpfreaks.com/topic/120789-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-624739 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.