Search code examples
phpmysqlzend-frameworkblobzend-db

Stream data in/out from Mysql BLOB using Zend Framework


I have done some googling and have failed miserably to find an answer to this...

Is it possible stream read/write some binary data from the local FS into a MySQL blob field using Zend Framework's Table/Row gateway classes?

Use Case (slightly contrived I know):

I have on my local FS a 100MB file and wish to store this in a DB (eeekk!). At the moment I'm forced to read this entire file into PHP's memory and then assign it to a Zend_Db_Table_Row_Abstract object before I can save the record to mysql. Is there anyway to assign the a stream to the row object so when I can save the row it just streams from the FS thus massively reducing memory consumption? (and I'd like to the opposite for reading from the DB)

Note: DB server and PHP server run on separate hardware/instances..

Apologies if I have missed some easy way to this or I am asking the impossible, it's just I seem to remember doing this with PostgreSQL and ZF easily enough.


Solution

  • Theoretical streaming should be possible as described in Large Objects (LOBs). In practise this is only true for writing. There's for more than 8 years an unresolved bug regarding reading streams. You'll have to chose another technology apart from PHP if you want to read streams.