note 103801 added to memcache.addserver
| From: | eu at serbannistor dot ro | Date: | Wed, 04 May 2011 13:30:15 +0000 |
| Subject: | note 103801 added to memcache.addserver | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179404@lists.php.net to get a copy of this message | ||
Actually if you have two memcached servers from which one of them is on localhost, and the other is
on a remote machine you can communicate with both even if you specify the loopback address for the
local one.
<?php
$memcache_obj = memcache_connect("127.0.0.1", 11211);
memcache_add_server($memcache_obj, "memcache_remote_host");
$memcache_obj->set('var_key', time());
?>
This WILL communicate with both hosts but however there are two aspects that must be taken into
account:
1. the communication will be done through different network interfaces with the two hosts. It will
use the loopback interface for the "127.0.0.1" host (lo in my case on Linux) and the
external interface for the "memcache_remote_host" (eth0 in my case). Only if you want to
use the same network interface to communicate with both hosts you must use the external IPs of both
machines (and all communication will go out through the eth0 interface).
2. the connection with the two hosts will be established differently because of how
memcache_connect() and memcache_add_server() work. Therefore the memcache_connect() will initiate
the connection to localhost through the loopback interface when it is called, while
memcache_add_server() will just add the second server to the pool, but it will not send any package
through the network until it's absolutely needed (for example when a memcache_set() command is
issued).
----
Server IP: 69.147.83.197
Probable Submitter: 193.105.64.1
----
Manual Page -- http://www.php.net/manual/en/memcache.addserver.php
Edit -- https://master.php.net/note/edit/103801
Del: integrated -- https://master.php.net/note/delete/103801/integrated
Del: useless -- https://master.php.net/note/delete/103801/useless
Del: bad code -- https://master.php.net/note/delete/103801/bad+code
Del: spam -- https://master.php.net/note/delete/103801/spam
Del: non-english -- https://master.php.net/note/delete/103801/non-english
Del: in docs -- https://master.php.net/note/delete/103801/in+docs
Del: other reasons-- https://master.php.net/note/delete/103801
Reject -- https://master.php.net/note/reject/103801
Search -- https://master.php.net/manage/user-notes.php