Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Image functions failing randomly when called

Status
Not open for further replies.

monkle

Programmer
Feb 11, 2004
132
US
I made a post here a while ago about this topic, but I've finally been able to put some time into it again, and I've made some progress. I'm up against another wall, though.

I have a php file that creates the thumbnail, and I call it in the <img> tag. I am calling the script multiple times on the page. Whether it shows the image correctly or shows a broken link seems to be completely random, even though the src url always shows the thumbnail correctly.

The code that I use to call the script is as follows:
Code:
echo "<img width = '96' height = '130' src = 'scripts/functions/thumb.php?upc=$upc' alt = 'IMG: {$title}'>";

The script that actually generates the thumbnail is as follows:
Code:
<?php
ob_start();
$upc = $_GET['upc'];
$turl = '[URL unfurl="true"]http://m4s-s1/images/';[/URL]
$tfilename = $upc.'_a.jpg';
$tfilepath = $turl.$tfilename;
list($width_orig, $height_orig) = getimagesize($tfilepath);
$image = imagecreatefromjpeg($tfilepath);
$image_p = imagecreatetruecolor(96, 130);
$width = 96;
$height = 130;
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
header("Content-type: image/jpeg");
$output .= imagejpeg($image_p);
?>

I have seen pages where this strategy works consistantly. I just haven't been able to find where my script breaks down. Like I say, when I access the script directly with the url, it works every time.
 
Hi,

The only issue that is see could be this:
I see taht you load the images from:
$turl = 'If you have a plenity of images you will open a lot of http connections to "m4s-s1", in the same time.
I bet that the number of concurent connections is limited.
So, as a debug method I recomad:
start the page with a feew images (2-3), see whats heppend.
If it's ok increase the number, and so on...
I'm sure that at a big number of images, some of them will fail.



Also, you can put the php to log the errors in some log file, and see whats happend.

No others ideas for now.

BTW: home many images are in your page ?



___
____
 
Thanks for the suggestions

I am using the thumbnail script on several pages, which could have anywhere 1-100 images on them. I have yet to make the page that only has one image on it break, however as few as 3 images will sometimes lose one or more (up to 3) images. I have one page that always has 14 images on it, and it usually loads all of the images, however sometimes it will lose several of them. Hitting F5 will usually load the images correctly, but not always.
 
Thanks for the suggestions

I am using the thumbnail script on several pages, which could have anywhere 1-100 images on them. I have yet to make the page that only has one image on it break, however as few as 3 images will sometimes lose one or more (up to 3) images. I have one page that always has 14 images on it, and it usually loads all of the images, however sometimes it will lose several of them. Hitting F5 will usually load the images correctly, but not always.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top