php - Speeding Up Image Loading from DB -


i'm loading 9 images database , syntax looks this:

<img src="image_loader.php?id=4"></img> 

my php image_loader.php looks like:

<?php     /* set connection using mysql_connect , mysql_select_db */      $query = sprintf("select ... ... id='".$_get["id"]."'");     $result = mysql_query($query, $con);     mysql_close($con);      if (!$result) {         // no result     }     else {         $row = mysql_fetch_row($result);          header('content-type: image/png');         echo $row[0];         mysql_free_result($result);         } ?> 

each image 10-13k bunch seems loading slow. realize there bottle-necking in number of requests browser can execute @ time wait times seem gratuitous.

any suggestions on how images loaded database fast?

also, , separate question, possible instruct browser (or server) cache images .gif/.png/.jpg srcs? seems firefox , chrome doesn't, i'm not of this.

enter image description here

i'd first consider whether storing images in database makes sense. may, should considered, giving each image unique filename in filesystem , storing that in database faster.

you gain additional speed if request file directly client opposed requesting generic php script sort of fopen()-style abstraction.

in order narrow down source of delay, first might helpful check whether database hosted on same server webserver. 1 indication not hosted locally on remote database server check host string you're providing in mysql_connect() call. localhost suggest local, else suggest it's not. note, many shared hosted services (e.g. godaddy) split database server webserver.

for better idea of source of delay, i'd suggest instrumenting image_loader.php code timestamps locate delay? guess it'll in query.

if delay is in query, want limit number of queries make. strategy allows make 1 query instead of 9 limit impact webserver-to-database server delay.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -