Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37916 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35144 invoked from network); 27 May 2008 13:07:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 May 2008 13:07:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=uwendel@mysql.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=uwendel@mysql.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mysql.com from 213.136.52.51 cause and error) X-PHP-List-Original-Sender: uwendel@mysql.com X-Host-Fingerprint: 213.136.52.51 mailgate-a.mysql.com Linux 2.6 Received: from [213.136.52.51] ([213.136.52.51:49273] helo=mailgate-a.mysql.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/B6-28982-3970C384 for ; Tue, 27 May 2008 09:07:32 -0400 Received: from mail.mysql.com (mailsend.mysql.com [10.100.1.123]) by mailgate-a.mysql.com (8.14.1/8.14.1) with ESMTP id m4RD5hcY007250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 27 May 2008 15:05:43 +0200 Received: from [10.16.64.235] (gmp-ea-fw-1.sun.com [192.18.1.36]) (authenticated bits=0) by mail.mysql.com (8.13.3/8.13.3) with ESMTP id m4RD7IZu020208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 27 May 2008 15:07:19 +0200 Message-ID: <483C0788.1020206@mysql.com> Date: Tue, 27 May 2008 15:07:20 +0200 User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: KishoreKumar Bairi CC: PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Streaming Enabled MySQL Driver for PHP - Google Summer of Code 2008 - MySQL From: uwendel@mysql.com (Ulf Wendel) 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) "//". 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[¶m=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