websupport-sk / pecl-memcache

PHP Extension - Memcache module with support of newer PHP 7.x and PHP 8.x
https://pecl.php.net/package/memcache
Other
328 stars 101 forks source link

Allow overriding the hardcoded retry timeout of 15 in php.ini for connect, as well as for connect/memcache_pconnect calls? #73

Closed TysonAndre closed 4 years ago

TysonAndre commented 4 years ago

E.g. this could be added to the options after $timeoutms in memcache_connect($host, $port, $timeout) and memcache_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

static void php_mmc_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool persistent) /* {{{ */
{
    zval *mmc_object = getThis();
    mmc_pool_t *pool;
    mmc_t *mmc;
    char *host;
    size_t host_len;
    zend_long tcp_port = MEMCACHE_G(default_port);
    double timeout = MMC_DEFAULT_TIMEOUT;

    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ld", &host, &host_len, &tcp_port, &timeout) == FAILURE) {
        return;
    }

Example use cases:

Zaffy commented 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.

TysonAndre commented 4 years ago

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)

Zaffy commented 4 years ago

Ah, ok. That should be easy to implement. I'll look into it.

Zaffy commented 4 years ago

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 ] ] ] ] ])
TysonAndre commented 4 years ago

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