Search code examples
laravelmemcachedshared-hosting

Laravel memcached not working in shared hosting


I've been trying to change the cache driver (CACHE_DRIVER) from file to memcached in production (shared host) where Memcached is set correctly and available according to phpinfo. Running still on Laravel 7.4.x

So far I've done the following:

  1. On the .env file I've changed the CACHE_DRIVER=file to CACHE_DRIVER=memcached;
  2. Checked the configuration in the config/cache.php as below:
<?PHP
'stores' => [
    'memcached' => [
        'driver'        => 'memcached',
        'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), // not required I think?...
        'sasl'          => [
            env('MEMCACHED_USERNAME'), // not required I think?...
            env('MEMCACHED_PASSWORD'), // not required I think?...
        ],
        'options'       => [
            // Memcached::OPT_CONNECT_TIMEOUT => 2000, // Ok
        ],
        'servers'       => [
            [
                'host'   => env('MEMCACHED_HOST', '127.0.0.1'), // set like in phpinfo
                'port'   => env('MEMCACHED_PORT', 11211),  // not required I think?...
                'weight' => 100, // Ok
            ],
        ],
    ],
    // ....
],
  1. Ran php artisan config:clear and php artisan cache:clear;
  2. Checked for existing cache tag. e.g. cache()->has('countries') and its false;
  3. Changed back to CACHE_DRIVER=file and started over. Result for cache()->has('countries') and its true

Either probably I'm missing something in the process, yet in local it's running on Memcached and for performance improvement, I'm trying to change it in production.

Thanks in advance for any inputs that might help me to solve this issue.


Solution

  • I won't delete the question (answering here) as it may help others facing the same problem on shared hostings.

    As @apokryfos mentioned the extension may be there but the Memcached server might not be available in all shared hostings, which is my case.

    If you have your projects on shared hosting and want to use Memcached, contact their support and ask if your plan contemplates the Memcached server. Otherwise, use other cache systems, namely and ultimately the file cache.