Jump to content

PHP script, slow execution help


lttg22

Recommended Posts

What I am doing is sort of a news script that grabs information from the first post in each news thread in a phpbb3 forum. That all works great and isn't the problem.

 

Now what I'm doing is replacing the img /img tags with <img src= and > using str_replace. That also works to, the final step I am doing is resizing the images if they are to big and this is where the problem is. It works but it slows down the execution time of my page by more then it should.

 

Here is the code I am using:

$image_link = SplitTwo($body[$i],"<img src=", ">");
$size = getimagesize($image_link);
if ($size[0] > 500) {
$body[$i] = str_replace("<img","<a href=$image_link><img alt=\"Image\" class=\"news\" ". imageresize($size[0],$size[1],500),$body[$i]);
}

 

Here is the SplitTwo function:

 

function SplitTwo($text,$first,$second) {
	$value = explode($first,$text);
	$value2 = explode($second,$value[1]);
	return $value2[0];
}

 

Here is the image resize function:

function imageResize($width, $height, $target) {
	if ($width > $height) {
	$percentage = ($target / $width);
	} else {
	$percentage = ($target / $height);
	}
	$width = round($width * $percentage);
	$height = round($height * $percentage);
	return "width=\"$width\" height=\"$height\" ";
} 

Link to comment
https://forums.phpfreaks.com/topic/158942-php-script-slow-execution-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.