amphp / redis

Efficient asynchronous communication with Redis servers, enabling scalable and responsive data storage and retrieval.

Home Page:https://amphp.org/redis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error while sending big data

vuliad opened this issue · comments

There is an error while sending long data to redis:

<?php
        \Amp\run(function () {
            $client = new \Amp\Redis\Client("tcp://localhost:6379");
            $data = [];
            for ($i = 0; $i < 1000; $i++) {
                $data['key' . $i] = mt_rand();
            }
            $stringData = serialize($data);
           $result = yield $client->set("dataArray", $stringData);
        });     
?>

And it throws error:

[08:08:19] critical ErrorException: fwrite(): send of 8192 bytes failed with errno=11 Resource temporarily unavailable in /var/www/travelm3/vendor/amphp/redis/lib/Connection.php:140
Stack trace:

0 [internal function]: League\BooBoo\Runner->errorHandler(8, 'fwrite(): send ...', '/var/www/travel...', 140, Array)

1 /var/www/travelm3/vendor/amphp/redis/lib/Connection.php(140): fwrite(Resource id #222, '*3\r\n$3\r\nset\r\n$9...')

2 /var/www/travelm3/vendor/amphp/amp/lib/UvReactor.php(420): Amp\Redis\Connection->Amp\Redis{closure}('000000005745667...', Resource id #222, NULL)

3 /var/www/travelm3/vendor/amphp/amp/lib/UvReactor.php(402): Amp\UvReactor->invokePollWatcher(Object(stdClass))

4 [internal function]: Amp\UvReactor->Amp{closure}(Resource id #225, 0, 2, Resource id #222)

5 /var/www/travelm3/vendor/amphp/amp/lib/UvReactor.php(93): uv_run(Resource id #62, 1)

6 /var/www/travelm3/vendor/amphp/amp/lib/functions.php(46): Amp\UvReactor->run(Object(Closure))

7 /var/www/travelm3/vendor/amphp/aerys/bin/aerys(96): Amp\run(Object(Closure))

8 {main}

With NativeReactor i get this error on every request. With uv reactor on second and next.

This is really critical.

Thanks for reporting!

Damn, that was fast! Thank you!

Now it's actually fixed.

It works properly with NativeReactor, but doesn't work with Uv for me - goes in infinite loop on redis->set(). As i see in .travis.yml - it tests only NativeReactor

That wasn't a trivial one ... Fixed in amp, tagged 1.2.1 there.

@vuliad May you try a composer.phar update please and check whether it works again?

[FTR: There were also some issues directly in php-uv extensions; you may want to rebuild that one too.]

Thanks a lot! Now it works well.

Just one thing - first i updated libuv\phpuv with this:

cd /tmp/ && mkdir libuv && (curl -L https://github.com/libuv/libuv/archive/v1.6.1.tar.gz | tar xzf -) && cd libuv-1.6.1 && ./autogen.sh && ./configure --prefix=$(readlink -f `pwd`/../libuv) && make && make install
 cd /tmp/ && git clone https://github.com/bwoebi/php-uv && cd php-uv && phpize && ./configure --with-uv=$(readlink -f `pwd`/../libuv) && make install

And i getting error:

phpdbg: src/unix/core.c:841: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
Aborted (core dumped)

After i update amp to 1.2.1 - it works great.

@vuliad Yep, uv requires no two different handles to point to a same file descriptor; due to a bug in amp we could create a new handle before actually closing the old handle - I had fixed that too.

commented

@kelunik Sorry for necro-comment. But I just looked at your fix.
Well, I'm using @ too. But I just use it to prevent reporting errors. But You've commented that you have fixed:

errno=11 Resource temporarily unavailable

I believe that you are just missed to explain what the fix do.
So in fact it won't help to send large data.
I suggest to split long data into small pieces and write them into socket one by one.
Thanks.