Skip to content

[BUG]: Phalcon\Storage\Adapter\Libmemcached wrong client config Memcached options override #16818

@tashik

Description

@tashik

Describe the bug
In getAdapter() method array_merge can not be used for merging memcached options from libmemcached client config and failovers variable, because all used \Memcached::[constant]s are numbers and array_merge reindex number-indexed arrays.

To Reproduce
From php if we try to override \Memcached options we get an error Cannot set Memcached client options

Steps to reproduce the behavior:

I have rewritten your code from getAdapter() method to show you the problem. I am sure in Zephir it works the same - array is reindexed and keys are changed.

    $options = [
        'persistentId' => 'ph-mcid-',
        'servers' => [
            ['host' => '127.0.0.1', 'port' => 11211, 'weight' => 1]
        ],
        'client' => [
            \Memcached::OPT_CONNECT_TIMEOUT => 1000,
            \Memcached::OPT_SERVER_FAILURE_LIMIT => 5,
            \Memcached::OPT_REMOVE_FAILED_SERVERS => false,
            \Memcached::OPT_RETRY_TIMEOUT => 5,
        ]
    ];

    $client = $options['client'];
    $failover = [
            \Memcached::OPT_CONNECT_TIMEOUT       => 10,
            \Memcached::OPT_DISTRIBUTION          => \Memcached::DISTRIBUTION_CONSISTENT,
            \Memcached::OPT_SERVER_FAILURE_LIMIT  => 2,
            \Memcached::OPT_REMOVE_FAILED_SERVERS => true,
            \Memcached::OPT_RETRY_TIMEOUT         => 1
    ];

    echo "Original client options:\n";
    print_r($client);
        
    echo "Phalcon failover defaults:\n";
    print_r($failover);
        
    $mergedClient = array_merge($failover, $client);
        
    echo "Merged client options:\n";
    print_r($mergedClient);

Expected behavior
Expected behaviour is to keep numeric keys after overriding failover with clien options, so we need to use array_replace or just clients + failover

Details

  • Phalcon version: 5.9.3
  • PHP Version: 8.*

Metadata

Metadata

Assignees

No one assigned

    Labels

    5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: mediumMedium

    Type

    No type

    Projects

    Status

    Implemented

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions