PHP lib ported to PHP5 and partially rewritten

175 views
Skip to first unread message

Salvatore Sanfilippo

unread,
Apr 22, 2009, 3:33:27 AM4/22/09
to redi...@googlegroups.com
Hello all,

as the result of a bug Albert Lombarte was experimenting with Redis
PHP (the replies were truncated) we found that the PHP client was not
playing well with PHP5 code for some reason. In order to fix the issue
I ported the original PHP lib to PHP5, removed references, and finally
rewrote a bit the code to read the reply in order to make it more
general about strange replies that we may use in the future (for
example nested multi bulk replies and so on). Moreover now the code
uses a different set of functions to read bulk data that should be
much faster (fread instead of gets). The new lib was not tested
extensively but it's passing the old tests without problems.

You can find the result inside the Redis-git. Note that some method
changed name to be more similar to the protocol itself: most of the
time I added aliases to avoid breaking code already using this lib,
but for "flush" that is now called "flushdb" without any aliasing.

Cheers,
Salvatore

--
Salvatore 'antirez' Sanfilippo
http://invece.org

Albert Lombarte

unread,
Apr 22, 2009, 7:15:22 AM4/22/09
to Redis DB
Thank you Salvatore for all the help you offered with this.

I tried the new php you passed but didn't work for me. But now I know
why.
I am using Multybyte encoding in my server and i have the methods
strpos, strlen, substr, etc... overloaded, so whenever any of this
functions are called it uses internally the multibyte equivalent of mb
(mb_strpos, mb_strlen, mb_substr).

The problem is that when the library uses these functions internally
it expects a single byte per character, but multibyte is passing more
than one for every character, so the communication with the socket is
unexpected.

I replaced all this functions with the equivalent "mb_" and added as a
parameter of all them "latin1" as the encoding for processing
commands. And now works perfect.

Salvatore, I am mailing you right now the file so you can add it to
the repo under redis_multibyte.php as a temporal solution for anyone
using this common feature.

Thank you very much for everything, now I'll start playing with the
database.

-- Albert Lombarte
http://splitweet.com

Salvatore Sanfilippo

unread,
May 4, 2009, 12:36:49 PM5/4/09
to redi...@googlegroups.com
On Wed, Apr 22, 2009 at 1:15 PM, Albert Lombarte <alom...@gmail.com> wrote:
>
> Thank you Salvatore for all the help you offered with this.

Thank you Albert,

just a question: is it common to override strlen() and other string
related functions? I'm not sure if I should add or not the change in
the global repo.

pcdinh

unread,
May 5, 2009, 2:41:00 AM5/5/09
to Redis DB

> just a question: is it common to override strlen() and other string
> related functions?

In some countries like Japan, China, Korea, Middle East countries ...
mb_* functions are used frequently. However, I don't think it is
common for the rest of the world. Therefore, it is better if we can
release 2 versions of the library: one for ASCII (better performance)
and one for multi-byte. Unicode support will not included into PHP
engine anytime soon: http://www.php.net/~scoates/unicode/render_func_data.php

Regards,

Dinh
Reply all
Reply to author
Forward
0 new messages