Re: Streaming Enabled MySQL Driver for PHP - Google Summer of Code 2008 - MySQL

From: Date: Tue, 27 May 2008 13:07:20 +0000
Subject: Re: Streaming Enabled MySQL Driver for PHP - Google Summer of Code 2008 - MySQL
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-37916@lists.php.net to get a copy of this message
Hi! KishoreKumar Bairi schrieb:
1. resource mysqli_get_blob ( mysqli link, string reference ) reference: is the string which used after database part in the referencing URL. It can be repository Id (or) "<table>/<column>/<row condition>".
PHP streams are a better choice than PHP strings for handling large string objects. PHP strings are loaded into memory at once. For a streaming engine you do not want to load large portions of data into memory unless you really have to. Why does this function return a resource? What type of resource is it and what is the resource handle used for?
2. string mysqli_put_blob ( mysqli link, string file_path, string mode , int length ) file_path: is the path of the file which is to be stored in a blob field. mode: mode specifier if the file should be read ASCII mode or binary mode.
PHP strings are binary safe. There are no ASCII mode strings. Why do you want to distinguish between ASCII and binary strings? Why is the functionality restricted to existing files? Looks a bit like its inspired by ftp or Windows? In general, I think such blob streaming functionality should use PHP streams. After some discussion with Andrey I'm not even sure if there is a need to introduce a single new API call to ext/mysqli. Andrey brought up the idea of using a streams protocol wrapper [1]. This would give you quite a neat API which is more powerful and flexible than the above suggestion. Here's an example in pseudo-code. Reading data from the blob repository: $stream = fopen('mysqlblob://user:password@socket/db/table/whateverid', 'r'); while ($chunk = fread($stream, 1024)) // read blob in 1k chunks echo $chunk; fclose($stream); Writing data from a file to the blob repository: $blob_stream = fopen('mysqlblob://user:password@host/https=0&id=/db/table/id', 'rw'); $file_stream = fopen('myimage.jpg'); $num_chunks = 0; while (stream_copy_to_stream($file_stream, $blob_stream, 1024) > 0) { printf("Writing to stream... %04dkb\n", $num_chunks++); } // the unique id generated by the blob engine to identify the blob $blob_id = fgets($blob_stream); fclose($file_stream); fclose($blob_stream); Generating data in PHP and writing to the blob repository: $blob_stream = fopen('mysqlblob://user:password@socket/options', 'w'); // create thumbnail $image = new Imagick('image.jpg'); $image->thumbnailImage(100, 0); fwrite($blob_stream, $image); // get unique blog id from the blob engine $blob_id = fgets($blob_stream); fclose($blob_stream); echo $image; And, and, and... - streams are a very mighty tool. I'm not sure about the syntax for connections. It could be something like this: URL: mysqlblob://user:password@[socket|host]?[param=value[&param=value...]] Params:
 id       - id of the blob to fetch/read
 port     - MySQL server port
 ssl      - SSL parameter
 ssh      - SSH parameter
Whatever you need. Ulf [1] http://www.php.net/manual/en/wrappers.php -- Ulf Wendel, MySQL Sun Microsystems GmbH, Sonnenallee 1, D-85551 Kirchheim-Heimstetten Geschaeftsfuehrer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer Vorsitzender des Aufsichtsrates: Martin Haering Muenchen: HRB161028

« previous php.internals (#37916) next »