Site is taking too long to load if there is a broken image

Discussion in 'PHP' started by baris22, Jan 24, 2009.

  1. #1
    hello all,

    I am just using

    
    <?=stripslashes($row[description])?>
    
    PHP:
    to show information from the database. The problem is if there is a broken image in there it takes ages for the page to load. it takes about 1-2 minutes.

    If the image is ok, there is no problem. it is loading so fast. (Sometimes it will load very fast even if the image is broken)

    what can i do to solve this problem?

    thanks
     
    baris22, Jan 24, 2009 IP
  2. Dennis M.

    Dennis M. Active Member

    Messages:
    119
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    The images will still be run through the PHP server but this may help site loading. I wrote a function to see if the image is a.) really an image or not and b.) if it's available or not. If it's not available the function will return false and from there you can (or if you give me more specifics I can) write a very quick (I'll leave an example) script to stop parsing the image.

    function chkImg($img){
    	$types = array("image/bmp","image/jpeg","image/pjpeg","image/jpg","image/pjpg","image/png","image/ppng","image/gif","image/pgif");
    	@$data  = getimagesize($img);
    	if(in_array($data['mime'],$types,true)){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    PHP:
    You could try something like this for the image check:
    
    <?php chkImg(string $img) ? true : die("You wouldn't really want to use a die here because it would stop operation but you get the point!"); ?>
    PHP:
    Regards,
    Dennis M.
     
    Dennis M., Jan 24, 2009 IP