Jump to content

Maximum execution time of 30 seconds exceeded


python01

Recommended Posts

I modified my file and now I get the message that the maximum execution time of 30 seconds is exceeded on line 121 or 106.

Not sure why it is happening because I only moved some of the code from the main program area into subroutine.

Before that it was running ok. I am posting the code below. Wonder if anyone can take a look at it and see what is holding it up.

I went through it few times but can not find the issue.

 

<?php
$PropertyID = $_GET["ID"];
include "./db/db_textback.inc.php";
?>

<?php

if(!isset($_GET['screen_check']))
{
//	$_GET['Width']=0;
/* This code will be executed if screen resolution has not been detected.*/
echo "<script type='text/javascript'>
<!-- 
document.location=\"?ID=$PropertyID&screen_check=done&Width=\"+screen.width+\"&Height=\"+screen.height;
//-->
</script>";
}
else 
{    
/* This code will be executed after screen resolution is detected.*/
    if(isset($_GET['Width'])){// && isset($_GET['Height'])) 
	// Resolution  detected
$ScreenWidth=$_GET['Width'] * 0.9;

     }
     else {
               // Resolution not detected
               	$ScreenWidth=235;
     }
}
echo "Screen width = ".$ScreenWidth;

?> 
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"/>
</head>


<?php

//$TelNumberQuery = mysql_query("SELECT * FROM Txtlog WHERE TelNumber = '$fromNumber'");
// $TelNumberNum = mysql_num_rows($TelNumberQuery);
//   $TelNumberInfo = mysql_fetch_array($TelNumberQuery);

function ImageSize($img, $maxwidth){
list($width, $height) = getimagesize($img);
if ($width>$maxwidth){
	$ratio=$maxwidth/$width;
	$newwidth=$maxwidth;
	$newheight=$height*$ratio;
}
else{
	$newwidth=$width;
	$newheight=$height;
}
echo $newwidth."  ".$newheight;
return array($newwidth, $newheight);
}

function AgentMessage($AgentInfoContent){

if($AgentInfoContent['DisplayName']!=NULL){
	echo $AgentInfoContent['DisplayName'];
}
else{
	echo $AgentInfoContent['FirstName']." ".$AgentInfoContent['LastName'];
}
?></br><?php
if($AgentInfoContent['Title']!=NULL){
	echo $AgentInfoContent['Title'];
?></br><?php
}
if($AgentInfoContent['Brokerage']!=NULL){
	echo $AgentInfoContent['Brokerage'];
?></br><?php
}
if($AgentInfoContent['Telephone']!=NULL && $AgentInfoContent['DisplayTelephone']==1){
	echo "Telephone: ".$AgentInfoContent['Telephone'];
?></br><?php
}
if($AgentInfoContent['Cell']!=NULL && $AgentInfoContent['DisplayCell']==1){
	echo "Cell: ".$AgentInfoContent['Cell'];
?></br><?php
}
if($AgentInfoContent['Fax']!=NULL && $AgentInfoContent['DisplayFax']==1){
	echo "Fax: ".$AgentInfoContent['Fax'];
?></br><?php
}
if($AgentInfoContent['Email']!=NULL && $AgentInfoContent['DisplayEmail']==1){
	echo "Email: ".$AgentInfoContent['Email'];
?></br><?php
}
}

function BodyDisplay(){
GLOBAL $PropertyInfo;
GLOBAL $Title;
GLOBAL $Count;
GLOBAL $PictureURL;
GLOBAL $PictureAlt;
GLOBAL $AgentInfo;
?>
<center><h3><?php echo $Title ?></h3></center>
<?php
//echo "Property id ".$PropertyID;
while($Index<4 && $Index<$Count){
if($PropertyPicsNum>0){
	$image=$PictureURL[$Index];
	$alt=$PictureAlt[$Index];
	list($newwidth, $newheight)=ImageSize($PictureURL[$Index],$ScreenWidth);

?>

<center> <img src="<?php echo $PictureURL[$Index];?>" alt="<?php echo $PictureAlt[$Index]; ?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" /> </center></br>
<?php
	$Index+=1;
}
?>


<?php
//$Index+=1;
}
if($PropertyInfo['MLS']!=NULL){
?>
<center><?php echo "MLS# ".$PropertyInfo['MLS']; ?></center></br>

<?php
}
if($PropertyInfo['Price']!=NULL){
?>
<center><?php echo "Price $".$PropertyInfo['Price']; ?></center></br>

<?php
}
if($PropertyInfo['WebDescription']!=NULL){
?>
<center><?php echo $PropertyInfo['WebDescription']; ?></center></br>
<?php
}
$AgentID=$PropertyInfo['AgentID'];
$AgentInfoQuery=mysql_query("SELECT * FROM Agents WHERE ID = $AgentID");
$AgentNum=mysql_num_rows($AgentInfoQuery);
if($AgentNum>0){
$AgentInfo=mysql_fetch_array($AgentInfoQuery);
if($AgentInfo['Picture']==NULL){
	AgentMessage($AgentInfo);
}
else{
$MaxAgentPicWidth=$ScreenWidth/10;
list($newagentwidth, $newagentheight)=ImageSize($AgentInfo['Picture'],$MaxAgentPicWidth);	
?>
<table border="0" width="100%">
<tr>
<td width="10%" valign="top" align="center"><img src="<?php echo $AgentInfo['Picture'];?>" alt="<?php echo $AgentInfo['DisplayName']; ?>" width="<?php echo $newagentwidth; ?>" height="<?php echo $newagentheight; ?></td>
<td width="90%" valign="top" align="left"><?php AgentMessage($AgentInfo); ?></td>
</tr>
</table>
<?php	
}
}

while($Index<$Count){
if($PropertyPicsNum>0){
	$image=$PictureURL[$Index];
	$alt=$PictureAlt[$Index];
	list($newwidth, $newheight)=ImageSize($PictureURL[$Index],$ScreenWidth);

?>

<center> <img src="<?php echo $PictureURL[$Index];?>" alt="<?php echo $PictureAlt[$Index]; ?>" width="<?php echo $newwidth; ?>" height="<?php echo $newheight; ?>" /> </center></br>
<?php
	$Index+=1;
}
}
}


//$PropertyID=2;
$PropertyPicsQuery=mysql_query("SELECT * FROM PropertyPics WHERE PropertyID = '$PropertyID'");
$PropertyPicsNum=mysql_num_rows($PropertyPicsQuery);
$Index=0;
while($PropertyPicsInfo=mysql_fetch_array($PropertyPicsQuery)){
$PictureURL[$Index]=$PropertyPicsInfo['PicURL'];
$PictureAlt[$Index]=$PropertyPicsInfo['PicAlt'];




$Index+=1;
}
$Count=$Index;
$Index=0;
$PropertyInfoQuery=mysql_query("SELECT * FROM Properties WHERE ID = $PropertyID");
$PropertyInfo=mysql_fetch_array($PropertyInfoQuery);
//echo "Number";
//echo $PropertyPicsNum;
$Title = $PropertyInfo['Number']." ".$PropertyInfo['Street'].", ".$PropertyInfo['City'].", ".$PropertyInfo['Province'];
?>
<body>
<?php
if($ScreenWidth<700){
BodyDisplay();
}
else{
BodyDisplay();
}
?>

</body>

Link to comment
Share on other sites

It's really difficult to follow the flow of your code because it keeps going in and out between HTML and PGP plus there is no structure to the PHP code - i.e. indenting of the code to show the logical structure. Personally, I would suggest separating the logic from the presentation as it makes for much cleaner code and these things are much easier to debug. (I'd also note I see the use of GLOBAL a lot which also points to poor practices)

 

But, I would bet that somewhere in that code you have queries being run in loops. Running many queries is always a bad idea, Most likely you can combine some queries using an appropriate JOIN to get the same results with just a single query.

 

But, YOU can easily find where the problems are by commenting out sections until the problem disappears. Then identify the section that is causing the problem. THEN you can post just that section to make it easier for us to help.

Link to comment
Share on other sites

Depending on your php.ini settings you may be able to increase your max execution time with set_time_limit().  You may have to change it directly in php.ini though, depending on your settings. 

 

But I would really fine-tooth your code first to make sure that it's doing what it is supposed to be doing, and just taking a long time.  For instance, you could be maxing the time because of an infinite loop or something...so on that note, I would start there.  Look at your loops.  Look at the variable(s) used in the conditions.  echo out the variables, see if they are changing value as expected, etc...

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.