php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65123 getStats() breaks connection
Submitted: 2013-06-25 12:03 UTC Modified: 2021-06-09 11:53 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: xavivg at gmail dot com Assigned: cmb (profile)
Status: Closed Package: memcached (PECL)
PHP Version: 5.3Git-2013-06-25 (Git) OS: Centos 5.9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: xavivg at gmail dot com
New email:
PHP Version: OS:

 

 [2013-06-25 12:03 UTC] xavivg at gmail dot com
Description:
------------
Using getStats() after a get() is anomalous. And no further set() or get() can be executed on same script.

Walking through these steps:
1.getStats()
2.get($key_name)
3.getStats()
4.getStats()
the 3rd return a pid of -1 while 1 and 4 are returning the valid connection

And this way
1.getStats()
2.get($key_name)
3.getStats()
4.get($different_key)
Makes get of step 4 return the content of step 2.

Test script:
---------------
// Creates new object
$Memcached = new Memcached('pepe');
$Memcached->setOption(Memcached::OPT_COMPRESSION, true);
$Memcached->setOption(Memcached::SERIALIZER_IGBINARY, true);
$Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);

// Connects to a pool of servers
$Memcached->addServer("127.0.0.1", "11211");
var_dump($Memcached->getStats());

$Memcached->set("Content 1", "This is content ONE");
var_dump($Memcached->getStats());

$Content = $Memcached->get("Content 1");
var_dump($Content);
var_dump($Memcached->getStats());

$Memcached->set("Content 2", "This is content TWO");
var_dump($Memcached->getStats());

$Content = $Memcached->get("Content 2");
var_dump($Content);
var_dump($Memcached->getStats());

Expected result:
----------------
It has to return always tha valid connection:
array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int 7008
      'uptime' => int 4200
      'threads' => int 4
      'time' => int 1372161606
      'pointer_size' => int 32
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 3999
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 18997
      'curr_items' => int 4
      'total_items' => int 26
      'limit_maxbytes' => int 16777216
      'curr_connections' => int 9
      'total_connections' => int 64
      'connection_structures' => int 10
      'bytes' => int 18692
      'cmd_get' => int 85
      'cmd_set' => int 27
      'get_hits' => int 54
      'get_misses' => int 31
      'evictions' => int 0
      'bytes_read' => int 45196
      'bytes_written' => int 339517
      'version' => string '1.4.5' (length=5)

array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int 7008
      'uptime' => int 4200
      'threads' => int 4
      'time' => int 1372161606
      'pointer_size' => int 32
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 3999
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 18997
      'curr_items' => int 4
      'total_items' => int 27
      'limit_maxbytes' => int 16777216
      'curr_connections' => int 9
      'total_connections' => int 64
      'connection_structures' => int 10
      'bytes' => int 18692
      'cmd_get' => int 85
      'cmd_set' => int 28
      'get_hits' => int 54
      'get_misses' => int 31
      'evictions' => int 0
      'bytes_read' => int 45280
      'bytes_written' => int 340972
      'version' => string '1.4.5' (length=5)

string 'This is content ONE' (length=19)

array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int 7008
      'uptime' => int 4200
      'threads' => int 4
      'time' => int 1372161606
      'pointer_size' => int 32
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 3999
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 18997
      'curr_items' => int 4
      'total_items' => int 26
      'limit_maxbytes' => int 16777216
      'curr_connections' => int 9
      'total_connections' => int 64
      'connection_structures' => int 10
      'bytes' => int 18692
      'cmd_get' => int 85
      'cmd_set' => int 27
      'get_hits' => int 54
      'get_misses' => int 31
      'evictions' => int 0
      'bytes_read' => int 45196
      'bytes_written' => int 339517
      'version' => string '1.4.5' (length=5)


array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int 7008
      'uptime' => int 4200
      'threads' => int 4
      'time' => int 1372161606
      'pointer_size' => int 32
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 3999
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 18997
      'curr_items' => int 4
      'total_items' => int 26
      'limit_maxbytes' => int 16777216
      'curr_connections' => int 9
      'total_connections' => int 64
      'connection_structures' => int 10
      'bytes' => int 18692
      'cmd_get' => int 85
      'cmd_set' => int 27
      'get_hits' => int 54
      'get_misses' => int 31
      'evictions' => int 0
      'bytes_read' => int 45196
      'bytes_written' => int 339517
      'version' => string '1.4.5' (length=5)


string 'This is content TWO' (length=19)

array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int 7008
      'uptime' => int 4200
      'threads' => int 4
      'time' => int 1372161606
      'pointer_size' => int 32
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 3999
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 18997
      'curr_items' => int 4
      'total_items' => int 26
      'limit_maxbytes' => int 16777216
      'curr_connections' => int 9
      'total_connections' => int 64
      'connection_structures' => int 10
      'bytes' => int 18692
      'cmd_get' => int 85
      'cmd_set' => int 27
      'get_hits' => int 54
      'get_misses' => int 31
      'evictions' => int 0
      'bytes_read' => int 45196
      'bytes_written' => int 339517
      'version' => string '1.4.5' (length=5)



Actual result:
--------------
array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int 7008
      'uptime' => int 4200
      'threads' => int 4
      'time' => int 1372161606
      'pointer_size' => int 32
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 3999
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 18997
      'curr_items' => int 4
      'total_items' => int 26
      'limit_maxbytes' => int 16777216
      'curr_connections' => int 9
      'total_connections' => int 64
      'connection_structures' => int 10
      'bytes' => int 18692
      'cmd_get' => int 85
      'cmd_set' => int 27
      'get_hits' => int 54
      'get_misses' => int 31
      'evictions' => int 0
      'bytes_read' => int 45196
      'bytes_written' => int 339517
      'version' => string '1.4.5' (length=5)

array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int 7008
      'uptime' => int 4200
      'threads' => int 4
      'time' => int 1372161606
      'pointer_size' => int 32
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 3999
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 18997
      'curr_items' => int 4
      'total_items' => int 27
      'limit_maxbytes' => int 16777216
      'curr_connections' => int 9
      'total_connections' => int 64
      'connection_structures' => int 10
      'bytes' => int 18692
      'cmd_get' => int 85
      'cmd_set' => int 28
      'get_hits' => int 54
      'get_misses' => int 31
      'evictions' => int 0
      'bytes_read' => int 45280
      'bytes_written' => int 340972
      'version' => string '1.4.5' (length=5)

string 'This is content ONE' (length=19)

array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int -1
      'uptime' => int 0
      'threads' => int 0
      'time' => int 0
      'pointer_size' => int 0
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 0
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 0
      'curr_items' => int 0
      'total_items' => int 0
      'limit_maxbytes' => int 0
      'curr_connections' => int 0
      'total_connections' => int 0
      'connection_structures' => int 0
      'bytes' => int 0
      'cmd_get' => int 0
      'cmd_set' => int 0
      'get_hits' => int 0
      'get_misses' => int 0
      'evictions' => int 0
      'bytes_read' => int 0
      'bytes_written' => int 0
      'version' => string '' (length=0)

array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int -1
      'uptime' => int 0
      'threads' => int 0
      'time' => int 0
      'pointer_size' => int 0
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 0
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 0
      'curr_items' => int 0
      'total_items' => int 0
      'limit_maxbytes' => int 0
      'curr_connections' => int 0
      'total_connections' => int 0
      'connection_structures' => int 0
      'bytes' => int 0
      'cmd_get' => int 0
      'cmd_set' => int 0
      'get_hits' => int 0
      'get_misses' => int 0
      'evictions' => int 0
      'bytes_read' => int 0
      'bytes_written' => int 0
      'version' => string '' (length=0)

boolean false

array (size=1)
  '127.0.0.1:11211' => 
    array (size=24)
      'pid' => int -1
      'uptime' => int 0
      'threads' => int 0
      'time' => int 0
      'pointer_size' => int 0
      'rusage_user_seconds' => int 0
      'rusage_user_microseconds' => int 0
      'rusage_system_seconds' => int 0
      'rusage_system_microseconds' => int 0
      'curr_items' => int 0
      'total_items' => int 0
      'limit_maxbytes' => int 0
      'curr_connections' => int 0
      'total_connections' => int 0
      'connection_structures' => int 0
      'bytes' => int 0
      'cmd_get' => int 0
      'cmd_set' => int 0
      'get_hits' => int 0
      'get_misses' => int 0
      'evictions' => int 0
      'bytes_read' => int 0
      'bytes_written' => int 0
      'version' => string '' (length=0)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-20 21:39 UTC] pep at neanderthal-technology dot com
Some more info:

First thing to note is that memcached keys are not allowed to contain 
whitespace. 
Source: https://github.com/memcached/memcached/blob/master/doc/protocol.txt line 
48. Quote:
"Keys
----

(....) the key must not include control characters or whitespace."



Second thing is that after replacing the spaces with underscores it still does 
not work the way expected. However, with 
OPT_BINARY_PROTOCOL turned off this problem does not occur.
When running memcached with -vv, the following happens on the getStats() call 
after the get(), causing the connection 
to be lost (full logs below):

<28 STATS
<28 Read binary protocol data:
<28    0x80 0x07 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
>28 Writing bin response:
>28   0x81 0x07 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
Failed to write, and not due to blocking: Broken pipe
<28 connection closed.

Executing other get or set commands does not cause this behaviour.


Environments tested:
------------
ubuntu 10.04 / php 5.3.2 / memcached 1.4.2 / libmemcached 1.0.2
centos 6.4 / php 5.4.15 / memcached 1.4.4 / libmemcached 1.0.10


Simplified test case:
---------------------
$Memcached = new Memcached();
$Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);

$Memcached->addServer("localhost", "11211");
$Memcached->set("Content_1", "This is content ONE");
$Content = $Memcached->get("Content_1");
var_dump($Content); // returns string(19) "This is content ONE"
var_dump($Memcached->getStats()); // returns array with pid "-1", connection is 
now gone


Full memcached logs:
--------------------
<28 new auto-negotiating client connection
28: Client using the binary protocol
<28 Read binary protocol data:
<28    0x80 0x01 0x00 0x09
<28    0x08 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x24
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28 SET Content_1 Value len is 19
>28 Writing bin response:
>28   0x81 0x01 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x02
<28 Read binary protocol data:
<28    0x80 0x0d 0x00 0x09
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x09
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28 GET Content_1
>28 Writing bin response:
>28   0x81 0x0d 0x00 0x09
>28   0x04 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x20
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
<28 Read binary protocol data:
<28    0x80 0x0a 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
>28 Writing bin response:
>28   0x81 0x0a 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
<28 Read binary protocol data:
<28    0x80 0x10 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28 STATS
<28 Read binary protocol data:
<28    0x80 0x07 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
<28    0x00 0x00 0x00 0x00
>28 Writing bin response:
>28   0x81 0x07 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
>28   0x00 0x00 0x00 0x00
Failed to write, and not due to blocking: Broken pipe
<28 connection closed.
 [2021-06-09 11:53 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-09 11:53 UTC] cmb@php.net
The memcached bug tracker is now on Github[1].  If this is still
an issue with the current memcached version, please report there.

[1] <https://github.com/php-memcached-dev/php-memcached/issues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 23:01:30 2024 UTC