Skip to content

Buffer writes not working as expected #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eduardosoliv opened this issue May 30, 2013 · 9 comments
Closed

Buffer writes not working as expected #78

eduardosoliv opened this issue May 30, 2013 · 9 comments
Labels
Milestone

Comments

@eduardosoliv
Copy link

Memcached::OPT_BUFFER_WRITES
Enables or disables buffered I/O. Enabling buffered I/O causes storage commands to "buffer" instead of being sent. Any action that retrieves data causes this buffer to be sent to the remote connection. Quitting the connection or closing down the connection will also cause the buffered data to be pushed to the remote connection.

Type: boolean, default: FALSE.

@ http://php.net/manual/en/memcached.constants.php

$ php -a
Interactive shell

php > $m = new \Memcached(); $m->addServer('....', 11211);
php > $m->set('test1', 10);
php > var_dump($m->get('test1'));
int(10)
php > $m->setOption(\Memcached::OPT_BUFFER_WRITES, true);
php > $m->set('test2', 20);
php > var_dump($m->get('test2'));
bool(false)
php > var_dump($m->getResultMessage());
string(9) "NOT FOUND"

I don't understand why there isn't a method like flush buffers, is already implemented at libmemcached:

http://docs.libmemcached.org/memcached_flush_buffers.html

@eduardosoliv
Copy link
Author

Ping

@mkoppanen
Copy link
Member

I will look at implementing this today.

@eduardosoliv
Copy link
Author

Great

@mkoppanen
Copy link
Member

The following seems to be working for me:

$m = new Memcached();
$m->addServer('127.0.0.1', 11211);
$m->setOption(Memcached::OPT_NO_BLOCK, 1);
$m->setOption(Memcached::OPT_BUFFER_WRITES, 1);

The documentation for libmemcached says that the writes will be flushed on get operation automatically. This doesn't seem to work without OPT_NO_BLOCK set to 1.

@eduardosoliv
Copy link
Author

That works:

php > $m = new Memcached();
php > $m->addServer('127.0.0.1', 11211);
php > $m->setOption(Memcached::OPT_NO_BLOCK, true);
php > $m->setOption(Memcached::OPT_BUFFER_WRITES, true);
php > $m->set('test2', 20);
php > var_dump($m->get('test2'));
int(20)

I didn't know is not present at documentation

Memcached::OPT_BUFFER_WRITES
Enables or disables buffered I/O. Enabling buffered I/O causes storage commands to "buffer" instead of being sent. Any action that retrieves data causes this buffer to be sent to the remote connection. Quitting the connection or closing down the connection will also cause the buffered data to be pushed to the remote connection.
Type: boolean, default: FALSE.
http://php.net/manual/en/memcached.constants.php

Neither here:
http://docs.libmemcached.org/memcached_behavior.html?highlight=buffer#MEMCACHED_BEHAVIOR_BUFFER_REQUESTS

But memcached lib have a flush buffers:
http://docs.libmemcached.org/memcached_flush_buffers.html

I think php-memcached should have too, don't you think?

@mkoppanen
Copy link
Member

I tested memcached_flush_buffers without NO_BLOCK set on and it doesn't seem to be working. I'll add flush buffers anyhow, as it probably works with NO_BLOCK

@eduardosoliv
Copy link
Author

I can't find anything on libmemcached documentation that point why don't work without NO_BLOCK (or that is expected), do you think is better to fill a bug report?

@mkoppanen
Copy link
Member

I'll try to create a reproducible test case in C and see if the issue persists. I've discovered other issues today as well so I can do the upstream report.

@sodabrew
Copy link
Contributor

sodabrew commented Jan 25, 2017

It's been a few years, can this issue be closed now? Is it resolved or wont-fix or still a problem?

Resolved, fixed, a new function $mc->flushBuffers() was added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants