php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57936 connect error
Submitted: 2007-11-29 23:08 UTC Modified: 2008-01-09 16:31 UTC
From: jjwang at tudou dot com Assigned:
Status: Closed Package: memcache (PECL)
PHP Version: 5.2.1 OS: CentOS 5
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: jjwang at tudou dot com
New email:
PHP Version: OS:

 

 [2007-11-29 23:08 UTC] jjwang at tudou dot com
Description:
------------
I wrote a test script fro memcache-3.0.0, but it seems not work correctly.

when set memcache.protocol to 'ascii', the output is:
ok: set, key-key_nmbccbbn
error: host-192.168.1.250 tcp_port-11211 udp_port-11200 error-Malformed VALUE header errnum-0
error: get, key-key_nmbccbbn
error: prepend, key-key_nmbccbbn
error: append, key-key_nmbccbbn
ok: now value is 
error: cas, key-key_nmbccbbn
ok: now value is 
error: increment, key-key_nmbccbbn
error: decrement, key-key_nmbccbbn
ok: now value is 
error: delete, key-key_nmbccbbn

when set memcache.protocol to 'binary', the output is:
error: host-192.168.1.250 tcp_port-11211 udp_port-11200 error-Network timeout errnum-0
error: set, key-key_ukdfwrwe
error: get, key-key_ukdfwrwe
error: prepend, key-key_ukdfwrwe
error: append, key-key_ukdfwrwe
ok: now value is 
error: cas, key-key_ukdfwrwe
ok: now value is 
error: increment, key-key_ukdfwrwe
error: decrement, key-key_ukdfwrwe
ok: now value is 
error: delete, key-key_ukdfwrwe

it seems that only set is succeed by 'ascii' protocol.

Reproduce code:
---------------
<?php
function getRandomString($prefix = '', $length = 8)
{
    $string = $prefix;
    for ($i = 0; $i < $length; $i++) {
        $string .= chr(rand(97, 122));  
    }
    return $string;
}

function failureCallback($host, $tcpPort, $udpPort, $error, $errnum)
{
    echo "error: host-$host tcp_port-$tcpPort udp_port-$udpPort error-$error errnum-$errnum<br />\n";
}

function testMemcache($memcache)
{    
    $key = getRandomString('key_');
    $value = getRandomString('value_');
    if (!$memcache->set($key, $value, 0, 60)) {
        echo "error: set, key-$key" . "<br />\n";
    } else {
        echo "ok: set, key-$key" . "<br />\n";
    }
    
    if (!($value = $memcache->get($key, $flags, $cas))) {
        echo "error: get, key-$key" . "<br />\n";
    } else {
        echo "ok: get, key-$key value-$value flags-$flags cas-$cas" . "<br />\n";
    }
    
    if (!$memcache->prepend($key, 'begin_')) {
        echo "error: prepend, key-$key" . "<br />\n";
    } else {
        echo "ok: prepend, key-$key" . "<br />\n";
    }
    if (!$memcache->append($key, '_end')) {
        echo "error: append, key-$key" . "<br />\n";
    } else {
        echo "ok: append, key-$key" . "<br />\n";
    }
    echo "ok: now value is " . $memcache->get($key) . "<br />\n";
    
    $value = getRandomString('value_');
    if (!$memcache->cas($key, $value, 0, 0, $cas)) {
        echo "error: cas, key-$key" . "<br />\n";
    } else {
        echo "ok: cas, key-$key value-$value cas-$cas" . "<br />\n";
    }
    echo "ok: now value is " . $memcache->get($key) . "<br />\n";
    
    $memcache->set($key, 7, 0, 60);
    if (!$memcache->increment($key)) {
        echo "error: increment, key-$key" . "<br />\n";
    } else {
        echo "ok: increment, key-$key" . "<br />\n";
    }
    if (!$memcache->decrement($key, 9)) {
        echo "error: decrement, key-$key" . "<br />\n";
    } else {
        echo "ok: decrement, key-$key" . "<br />\n";
    }
    echo "ok: now value is " . $memcache->get($key) . "<br />\n";
    
    if (!$memcache->delete($key)) {
        echo "error: delete, key-$key" . "<br />\n";
    } else {
        echo "ok: delete, key-$key" . "<br />\n";
    }
}

ini_set('memcache.protocol', 'binary');
$memcache = new MemcachePool();
$memcache->addServer('192.168.1.250', 11211, 11200);
$memcache->setFailureCallback('failureCallback');
testMemcache($memcache);
?>

Expected result:
----------------
I need UDP interface of memcache, but I found no message in README. How can I choose to use 'TCP' or 'UDP'?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-30 01:06 UTC] mikael at synd dot info
Please verify that you have the correct port numbers and a recent udp-capable memcached version installed (like version 1.2.3). You must also start it like

 memcached -p 11211 -U 11200

Also be sure not to set protocol to binary when attempting to connect to a regular memcached instance listening on its -p (tcp/ascii) port. When using the binary protocol memcached must be started using -B <binary tcp port>, also the current binary protocol capable server does not support binary protocol over UDP. Memcached listens on separate ports for ascii-tcp, ascii-udp, binary-tcp so the portnumbers and protocol settings may not be mixed.

If that fails, please provide an strace that shows the first couple of failed operations. For example

 strace php mytestscript.php

If UDP is enabled pecl/memcache will use it for gets, while sending set/delete/increment/.. operations on the TCP port, this means you need the server listening on both tcp and udp ports.
 [2007-11-30 01:42 UTC] jjwang at tudou dot com
I download memcached-1.2.4-rc1 and make a new memcached, it works! 
But I can't start memcached with -B option, and when using 'ascii' protocol, decrement operation failed when value is down to zero. Thanks!
 [2007-11-30 03:59 UTC] jjwang at tudou dot com
Another problem:)
When $loops=100, the fallowing code consumes 3s, but when set $loops to 1000, the program do not finish in several minutes, and there is a lot tcp connection at TIME_WAIT stat in client machine(192.168.1.99), server(10.5.22.51) side is ok.

$start = time();
    for ($i = 0; $i < $loops; $i++)
    {
        $memcacheTCPShort->connect('10.5.22.51', 11211, 0, false);
        if (!$memcacheTCPShort->get($key)) {
            echo "error: get by tcp, key-$key" . "<br />\n";
        }
        $memcacheTCPShort->close();
    }
    $end = time();
    echo "ok: get by tcp short consumes " . ($end - $start) . "seconds<br />\n";

output of 'netstat -nt | grep 11211' at client side:
tcp        0      0 192.168.1.99:44389          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44388          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44391          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44390          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44385          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44384          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44387          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44386          10.5.22.51:11211            TIME_WAIT   
tcp        0      0 192.168.1.99:44365          10.5.22.51:11211            TIME_WAIT   
...
 [2008-01-09 16:31 UTC] mikael at synd dot info
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC