php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60460 Memcache->close() does not close opened addServer sockets
Submitted: 2011-12-07 16:40 UTC Modified: 2011-12-27 10:37 UTC
From: riccardo dot bonciani at dada dot eu Assigned:
Status: Closed Package: memcache (PECL)
PHP Version: 5.3.8 OS: Linux Kernel 2.6.20.1
Private report: No CVE-ID: None
 [2011-12-07 16:40 UTC] riccardo dot bonciani at dada dot eu
Description:
------------
Memcache->close() does not close connections of opened sockets to memcache servers. This is only for connections created by addServer methods.
It's all ok for connections created by the connect method.




---
From manual page: http://www.php.net/memcache.addserver#refsect1-memcache.addserver-description
---


Test script:
---------------
// This closes connection
$memcache = new Memcache;
$memcache->connect('memcache.server', 11211);
$memcache->get('sample');
$memcache->close();
echo shell_exec('tree /proc/'.getmypid().'/fd/')."\n";

// This does not close connection
$memcache = new Memcache;
$memcache->addServer('memcache.server', 11211);
$memcache->get('sample');
$memcache->close();
echo shell_exec('tree /proc/'.getmypid().'/fd/')."\n";

Expected result:
----------------
I expect not viewing the socket file descriptor.

/proc/23592/fd/
|-- 0 -> /dev/pts/10
|-- 1 -> /dev/pts/10
|-- 2 -> /dev/pts/10
`-- 3 -> pipe:[193952992]

/proc/23592/fd/
|-- 0 -> /dev/pts/10
|-- 1 -> /dev/pts/10
|-- 2 -> /dev/pts/10
`-- 3 -> pipe:[193953002]


Actual result:
--------------
/proc/23592/fd/
|-- 0 -> /dev/pts/10
|-- 1 -> /dev/pts/10
|-- 2 -> /dev/pts/10
`-- 3 -> pipe:[193952992]

/proc/23592/fd/
|-- 0 -> /dev/pts/10
|-- 1 -> /dev/pts/10
|-- 2 -> /dev/pts/10
|-- 3 -> socket:[193953001]
`-- 4 -> pipe:[193953002]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-07 17:41 UTC] riccardo dot bonciani at dada dot eu
This issue is very important regarding to the fork behaviour. 
After many pcntl_fork() all children share the same memcache socket, which was opened by the parent process.
 [2011-12-27 09:59 UTC] luca dot pasquali at dada dot eu
it is quite clear in documentation that:

Memcache::addServer() does a *presistent* connection by default, if you do not 
specify it to be different.

memcache::close() function doesn't close persistent connections, which are closed 
only during web-server shutdown/restart.

so this is not a bug at all, but a coding error.
 [2011-12-27 10:37 UTC] riccardo dot bonciani at dada dot eu
Tnx Luca,
You are right. We should set the third parameter to false.

addServer(server, port, false)

The documentation is quite confusing because the first lines:

"Memcache::addServer() adds a server to the connection pool. The connection, 
which was opened using Memcache::addServer() will be automatically closed at the 
end of script execution, you can also close it manually with Memcache::close()."
 [2011-12-27 10:37 UTC] riccardo dot bonciani at dada dot eu
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 20:01:31 2024 UTC