trogne's avatar

proper way to override vendor config

In Lumen, there's no app/config folder.

So, for a heroku site, when deploying, all changes that was made to vendor config folders will be lost.

Say I want "memcached" to be configured.

There's a "cache.php" under "vendor\laravel\lumen-framework\config".

How to I override "cache.php" ?

I don't think it's by copying the "cache.php" to a new "config" folder under "app/"...

0 likes
2 replies
einsteinpp's avatar

Everything is in the .env file, you should never edit a fil in the vendor directory.

trogne's avatar

If using heroku "MemCachier", we need to change the vendor config file.

So it's not possible with lumen on heroku.

This is the default lumen vendor cache config for memcached :

        'memcached' => [
            'driver' => 'memcached',
            'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
            'sasl' => [
                env('MEMCACHED_USERNAME'),
                env('MEMCACHED_PASSWORD'),
            ],
            'options' => [
                // Memcached::OPT_CONNECT_TIMEOUT  => 2000,
            ],
            'servers' => [
                [
                    'host' => env('MEMCACHED_HOST', '127.0.0.1'),
                    'port' => env('MEMCACHED_PORT', 11211),
                    'weight' => 100,
                ],
            ],
        ],

And this is what we need for MemCachier :

'memcached' => [
    'driver' => 'memcached',
    'persistent_id' => 'memcached_pool_id',
    'sasl' => [
        env('MEMCACHIER_USERNAME'),
        env('MEMCACHIER_PASSWORD'),
    ],
    'options' => [
        // some nicer default options
        // - nicer TCP options
        Memcached::OPT_TCP_NODELAY => TRUE,
        Memcached::OPT_NO_BLOCK => FALSE,
        // - timeouts
        Memcached::OPT_CONNECT_TIMEOUT => 2000,    // ms
        Memcached::OPT_POLL_TIMEOUT => 2000,       // ms
        Memcached::OPT_RECV_TIMEOUT => 750 * 1000, // us
        Memcached::OPT_SEND_TIMEOUT => 750 * 1000, // us
        // - better failover
        Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
        Memcached::OPT_LIBKETAMA_COMPATIBLE => TRUE,
        Memcached::OPT_RETRY_TIMEOUT => 2,
        Memcached::OPT_SERVER_FAILURE_LIMIT => 1,
        Memcached::OPT_AUTO_EJECT_HOSTS => TRUE,

    ],
    'servers' => array_map(function($s) {
        $parts = explode(":", $s);
        return [
            'host' => $parts[0],
            'port' => $parts[1],
            'weight' => 100,
        ];
      }, explode(",", env('MEMCACHIER_SERVERS', 'localhost:11211')))
],

See https://www.memcachier.com/documentation/laravel

So it would be only possible if we could override (with Lumen) the memcache config outside of the vendor folder.

Same with MemcacheCloud I guess.

Please or to participate in this conversation.