php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62714 memcached persistence in PHP does not work as expected
Submitted: 2012-08-01 10:21 UTC Modified: 2021-06-09 11:32 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: aw at ez dot no Assigned: cmb (profile)
Status: Closed Package: memcached (PECL)
PHP Version: Irrelevant OS: Red Hat Enterprise Linux Server
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: aw at ez dot no
New email:
PHP Version: OS:

 

 [2012-08-01 10:21 UTC] aw at ez dot no
Description:
------------
i have played a bit around with different memcached library and plugin version to enable real persistence between PHP memcache client and memcached server.

The problem is that still connections are opened and closed so that the connection counter goes up instead of the reusage of a existing persistent connection.

I have compiled the memcached daemon on from newest source on a redhat machine. I use the version memcached-1.4.14 and started with "#/opt/memcached/bin/memcached -vvvv"

The php plugin i have also compiled from newest source version memcached-2.0.1, i have compiled it against libmemcached-1.0.9 to have it up to date. Currently it does not compile against libmemcached-1.0.10.

On firing the script i see in the output that servers are not added, only after timeout period.

Array ( [@�qVG:11211] => Array ( [pid] => 3728 [uptime] => 73 [threads] => 4 [time] => 1343813688 [pointer_size] => 64 [rusage_user_seconds] => 0 [rusage_user_microseconds] => 6998 [rusage_system_seconds] => 0 [rusage_system_microseconds] => 31995 [curr_items] => 37 [total_items] => 37 [limit_maxbytes] => 67108864 [curr_connections] => 38 [total_connections] => 47 [connection_structures] => 39 [bytes] => 3589 [cmd_get] => 37 [cmd_set] => 37 [get_hits] => 37 [get_misses] => 0 [evictions] => 0 [bytes_read] => 3267 [bytes_written] => 39458 [version] => 1.4.14 ) )

But the connection counter still goes up and i suppose that the client creates a connection and on server side the persistent connection is re-used. 

#netstat -an | grep 11211 | wc -l

tcp        0      0 ::1:11211                   ::1:55941                   VERBUNDEN   
tcp        0      0 ::1:55961                   ::1:11211                   VERBUNDEN   
tcp        0      0 ::1:55959                   ::1:11211                   VERBUNDEN   
tcp        0      0 ::1:11211                   ::1:56005                   VERBUNDEN   
...and so on

On server side i get verbous output that tells me that persistence is used:
...
<43 get persistentkey_5018f83903ded
> FOUND KEY persistentkey_5018f83903ded
>43 sending key persistentkey_5018f83903ded
>43 END
...

We want to use memcache on a high performance environment with a lot of incomming connections, and the connection amout does kill the apache childs currently.

Used software:

    Red Hat Enterprise Linux Server release 6.2 (Santiago)
    PHP Version 5.3.3
    Apache/2.2.15 in Prefork
    Memcache server 1.4.14
    libmemcached 1.0.9
    PHP memcached plugin 2.0.1


Test script:
---------------
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

$key = "key_" . uniqid();
$memcached = new Memcached( 'persistent' );
$memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$memcached->setOption(Memcached::OPT_RECV_TIMEOUT, 1000);
$memcached->setOption(Memcached::OPT_SEND_TIMEOUT, 3000);
$memcached->setOption(Memcached::OPT_TCP_NODELAY, true);
$memcached->setOption(Memcached::OPT_PREFIX_KEY, 'persistent');

if( !count($memcached->getServerList() ) )
{
    $memcached->addServer( 'localhost', 11211 );
}
$memcached->set($key, 'value');
$value = $memcached->get($key);

print_r( $memcached->getStats() );
?>

Expected result:
----------------
Only a small amount of connections to memcache server which are persistent.

Actual result:
--------------
tcp        0      0 ::1:11211                   ::1:55941                   VERBUNDEN   
tcp        0      0 ::1:55961                   ::1:11211                   VERBUNDEN   
tcp        0      0 ::1:55959                   ::1:11211                   VERBUNDEN   
tcp        0      0 ::1:11211                   ::1:56005                   VERBUNDEN 

a huge amount of open connections which can be counted with

#netstat -an | grep 11211 | wc -l


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-09 11:32 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-09 11:32 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: Sun May 26 10:01:33 2024 UTC