Lumen is very popular,fast and light weight api micro-framework by Laravel using php. I have created many project on lumen framework.This tutorial help to configuration of memcached with lumen 5.1.*
version.
There is no clear step by step docs available about configuration of memcached
and uses in Lumen rest framework.I will share step by step lumen tutorial for memcached configuration with centOS 7,I am using below configuration of Lumen host server.
Please keep in mind do not try with windows server there is no memcached extension available for xampp
/wamp
server.You can get memcache.so
but not memcached.so
(‘d’) php extension.
If you will use with windows, you will get memcached is not available at …line 38.I wastage much time to find windows ext but unfortunately did not work for me.We will follow below steps to add Memcached with Lumen,
.env
fileYou can also check other recommended tutorials of Lumen/Laravel,
Lets start configuration of memcached with lumen,
Step 1: We need to update .env
file of Lumen project and added Cache driver Memcached.
CACHE_DRIVER=memcached
Step 2: Copy cache.php
file from lumen_project\vendor\vendor\laravel\lumen-framework\config\
and put into lumen_project\config\
folder,If config folder is not present in Lumen root create and put cache.php
file.
Step 3: Now change value of default cache driver from array to memcached into lumen_project\config\cache.php
file.
'default' => env('CACHE_DRIVER', 'memcached'),
Step 4: Now we will install memecahed server on Centos and php extention.
yum -y install memcached yum install php-pecl-memcached
Step 5: Now we will restart ngnix
,fpm
to update php.ini
configuration and memcached server using below Linux command.
service php-fpm restart service memcached restart service nginx restart
You can see memcached extension enabled in phpinfo
file.If you are not getting memcached extension in phpinfo
file then some thing wrong.
Step 1: Set variable in memcached using set()
function.
public function setMemcache() { Cache::put('name', 'parvez', 15); }
I have set 15 min for this cache object time limit after that object will flush from Memcached.
Step 2: Set variable in Memcached using get()
function.
/** * Method to getter method for memcached * * @author parvez.alam */ public static function getMemcache() { echo Cache::get('name'); }
if not key available in Memcached then it will return false;
That’s all for Memcached configuration and uses with Lumen,I have shared this tutorial for all Lumen api framework and Memcached lover, you can use with other php api framework as well but need to change set()
and get()
method of object as per your php api framework docs.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More
View Comments
i follow above steps but still generating Error.
Class 'Memcached' not found so what i do and where i change it.
i think memcached not installed correctly or service not started, if u are on nginx, please restart php-fpm