Jump to content

Fatal error: Maximum execution time of 30 seconds exceeded


ballhogjoni

Recommended Posts

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 );
	}
}
}
?>

 

Link to comment
Share on other sites

	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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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()

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.