Thread: faster way to display jpg-blobs?

faster way to display jpg-blobs?

From
Knut Suebert
Date:
Hello,

I'm new to this list.

And I have the following question: is there a better/faster way than the
following to read jpeg-blobs out of the database and display them?

  if( $db->next_record() ){
    header("Content-Type: image/jpeg");
    $bild = $db->lo_read($db->f("oid"));
    header("Content-Length: 1024000"); // has to be calculated
    print($bild);
  }

where lo_read() is

  function lo_read($oid, $mode="r"){
    $this->connect();
    pg_exec($this->Link_ID, "begin"); // a must for blob-operations
    if( $lo_id = pg_loopen( $this->Link_ID, $oid, $mode ) ){
      $lo = pg_loread( $lo_id, 1024000 ); // has to be calculated
      pg_loclose($lo_id);
    }
    pg_exec($this->Link_ID, "end");
    return $lo; // empty leer, wenn auslesen gescheitert
  }

Because of the begin/end every picture on a page is loaded one after the
other, I fear. Not simultaneous as if there would be a direct <img
src='pic_N.jpg'> instead of <img src='pic.php?id=N'>.

Using blobs is a must IMHO, as viewing the pics should only be possible for
authorized people.

Thanks, bye,
Knut






Re: faster way to display jpg-blobs?

From
Knut Suebert
Date:
Knut Suebert schrieb:

> And I have the following question: is there a better/faster way than the

>     header("Content-Length: 1024000"); // has to be calculated

has to be calculated, as i wrote. without an unexpected EOF the thing is
fast enough.

sorry,
knut

Re: faster way to display jpg-blobs?

From
"Brent R. Matzelle"
Date:
3/18/2001 7:22:35 AM, Knut Suebert <knut.suebert@web.de> wrote:
>Because of the begin/end every picture on a page is loaded one after the
>other, I fear. Not simultaneous as if there would be a direct <img
>src='pic_N.jpg'> instead of <img src='pic.php?id=N'>.

You can put a BEGIN/END around multiple queries to place all queries into one
transaction block and thus rid yourself of some overhead.  Otherwise I do not
know of any _faster_ way to download binary data from a database.  I would
suggest that you place the images on the fs instead and provide a (VARCHAR)
path to the file, but that option is dependent upon your web system.

Brent