From:             support at kalador dot com
Operating system: redhat linux
PHP version:      5.1.2
PHP Bug Type:     Performance problem
Bug description:  extremely slow bytea extraction from pgsql

Description:
------------
I tried 3 ways to store big images (500K) in database and display in
browser.  lo works fast, as does using a "text" column and converting the
image to base64 (and back for display). However, using bytea with escaping
is very slow.

Adding to the database is fine (it is fast), retrieving is the problem.



Reproduce code:
---------------
This code consumed my CPU and took 77 seconds to run for a 400K image:

<?php
 // Connect to the database
 $dbconn = pg_connect('dbname=imagedb');

 // Get the bytea data
 $res = pg_query("SELECT data FROM image WHERE name='big.gif'");

 // Convert to binary and send to the browser
 header('Content-type: image/gif');
 echo pg_unescape_bytea( pg_fetch_result($res,'data') );
?>


Expected result:
----------------
This should take less than 1 second.  Using a text column and base64
escaping rather than a bytea column and pg_unescape_bytea takes less than
1 second on the same data.

Actual result:
--------------
Actually result - 77 seconds.

-- 
Edit bug report at http://bugs.php.net/?id=36278&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=36278&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=36278&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=36278&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=36278&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=36278&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=36278&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=36278&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=36278&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=36278&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=36278&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=36278&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=36278&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=36278&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=36278&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=36278&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=36278&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=36278&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=36278&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=36278&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=36278&r=mysqlcfg

Reply via email to