Closed TysonAndre closed 4 years ago
The docs are obsolete, but the API supports this and should work just fine. Just pass third parameter to connect/pconnect.
object memcache_connect(string host [, int port [, double timeout ] ])
object memcache_pconnect(string host [, int port [, double timeout ] ])
You can also see from the code snippet you posted that although timeout is initialized to MMC_DEFAULT_TIMEOUT
it gets overridden immediately by optional timeout parameter, if provided.
I'd assumed that the timeout
applied to the initial connection attempt. (The one in the snippet - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ld", &host, &host_len, &tcp_port, &timeout) == FAILURE) {
)
However, I'm looking for a way to the retry_timeout
, which is used when memcache reconnects if the initial connection breaks (e.g. idle for a long time and disconnected by the load balancer or server). When I looked at the code, the former didn't seem to affect the latter
So something more like memcache_pconnect($host, $port = default, $timeout = default, $retry_timeout = 15)
Ah, ok. That should be easy to implement. I'll look into it.
Perhaps these APIs would suffice you?
bool memcache_set_server_params( memcache, string host [, int port [, double timeout [, int retry_interval [, bool status [, callback failure_callback ] ] ] ] ])
bool Memcache::setServerParams( string host [, int port [, double timeout [, int retry_interval [, bool status [, callback failure_callback ] ] ] ] ])
I'd overlooked those, those may help. They weren't documented on php.net when I checked, so I didn't realize they were an option - https://www.php.net/manual-lookup.php?pattern=memcache_set_server_params&lang=en&scope=404quickref
PRs can be made to https://github.com/php/doc-en
EDIT: Never mind, it's already there: https://www.php.net/manual/en/memcache.setserverparams
E.g. this could be added to the options after $timeoutms in
memcache_connect($host, $port, $timeout)
andmemcache_pconnect()
.It's possible through addServer but not pconnect()
https://www.php.net/manual/en/memcache.addserver.php
The c code doesn't seem to have a way to do this in 4.0.5
Example use cases: