How to configure memcache in php
This article mainly introduces how to configure memcache in PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
1. Memcache concept
First of all We must distinguish three concepts: Memcached, memcache and memcached.
1. Memcached refers to the Memcached server, which is an independently running Memcached background server. Just like mysqld, it is a key-value pair used to store data. "Database".
2. Memcached and memcache are both Memcached clients, and you can access and connect to the Memcached server through them. They are both PHP plug-ins. The difference between the two is an old topic, you can refer to Other articles say. I personally feel that memcached is better. After all, it has many functions and is based on the extension of libmemcached.
2. Memcached server installation and testing
If it is fedora, there are built-in sources memcached, you can install it directly with yum
yum -y install memcached.x86_64
After installation, start the background process.
memcached -d -m 10 -u user -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached.pid
Among them, -d means to start the background service process, -m means the maximum use of 10m memory, -u means the current User, -l represents the ip address, -p represents the port number, -c represents the maximum number of concurrent connections, and -P represents the location of the pid file. Other parameters can be directly queried by man memcached.
Now you can use telnet to test Next, check the opening status of memcached.
telnet 127.0.0.1 12000Trying 127.0.0.1...Connected to 127.0.0.1. Escape character is '^]'. set a 0 0 41234STORED get a VALUE a 0 41234END ^C quit
The above message indicates that the Memcached server is installed successfully.
3. Installation and testing of memcache
wget -c http://pecl.php.net/get/memcache-3.0.8.tgztar zxvf memcache-3.0.8.tgz phpize && ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-configmake && make install
In this way, a line of Installing shared extensions will appear below: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
The so file is generated, and then just import this module in the php.ini file.
extension_dir=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/extension=memcache.so
Then restart php-fpm to load php.ini, check phpinfo. If you see memcached, it means the module installation is successful. Sometimes php.ini may not be loaded. You can force php-fpm to load the ini file.
php-fpm -c /usr/local/php/lib/php.ini
Test memcached in the php file.
<?php $memcache = memcache_connect('localhost', 12000); if ($memcache) { $memcache->set("key1", "String"); $memcache->set("key2", 123); $object = new StdClass; $object->attribute = 'test'; $memcache->set('key3', $object); var_dump($memcache->get('key1')); var_dump($memcache->get('key2')); var_dump($memcache->get('key3')); } else { echo "Connection to memcached failed"; } ?>
You can know whether the access is successful by accessing it through the browser.
There is a file called memcache.php in memcache, you can check the operation of the memcache server Status.
Modify the memcache.php file.
#$MEMCACHE_SERVERS[] = 'mymemcache-server1:11211'; // add more as an array #$MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array $MEMCACHE_SERVERS[] = 'localhost:12000';
You can see the status of the memcached server when you open the browser.
4. Installation and testing of memcached
Installation It’s similar to memcache, but you need to install libmemcached first.
yum -y install libmemcached.x86_64
Then just follow the installation and testing methods of memcache.
The above is the entire content of this article, I hope it will be helpful to everyone’s study , please pay attention to the PHP Chinese website for more related content!
Related recommendations:
About recursive analysis in php
The above is the detailed content of How to configure memcache in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

With the development of the Internet, PHP applications have become more and more common in the field of Internet applications. However, high concurrent access by PHP applications can lead to high CPU usage on the server, thus affecting the performance of the application. In order to optimize the performance of PHP applications, Memcached caching technology has become a good choice. This article will introduce how to use Memcached caching technology to optimize the CPU usage of PHP applications. Introduction to Memcached caching technology Memcached is a

How to use Memcache for efficient data writing and querying in PHP development? With the continuous development of Internet applications, the requirements for system performance are getting higher and higher. In PHP development, in order to improve system performance and response speed, we often use various caching technologies. One of the commonly used caching technologies is Memcache. Memcache is a high-performance distributed memory object caching system that can be used to cache database query results, page fragments, session data, etc. By storing data in memory

In PHP development, using the Memcache caching system can greatly improve the efficiency of data reading and writing. Memcache is a memory-based caching system that can cache data in memory to avoid frequent reading and writing of the database. This article will introduce how to use Memcache in PHP for efficient data reading and writing operations, and provide specific code examples. 1. Install and configure Memcache First, you need to install the Memcache extension on the server. able to pass

As web applications become increasingly complex, performance has become a critical issue. In many applications, database queries are one of the most time-consuming operations. In order to avoid frequently reading data from the database, a caching system can be used to store frequently read data in memory for quick access. In PHP development, using Memcached for distributed caching is an extremely common practice. In this article we will introduce how to use Memcached for distributed caching. What is Memca

How to use Memcache to optimize data storage operations in your PHP application? In web application development, data storage is a crucial link. In PHP applications, Memcache, as a memory cache system, can effectively improve the efficiency of data storage and reading operations. This article will introduce how to use Memcache to optimize data storage operations in PHP applications, and attach specific code examples. Step 1: Install the Memcache extension First, you need to install Me in your PHP environment

With the development of the Internet, caching technology plays an increasingly important role in Web development. Redis and Memcached, two popular cache servers, are widely used in various web application development. However, for developers who are not familiar with Linux systems, installing and configuring these cache servers can cause some trouble. However, with the help of Pagoda Panel, this process will become quite simple. 1. What is a pagoda panel? Pagoda panel is a Linux server management panel that can

PHP is a very popular programming language commonly used for server-side web application development. As the user scale of web applications continues to grow and the amount of data continues to increase, efficient data caching and sorting operations become more and more important. Memcache is a very useful tool in this situation. This article will introduce how to use Memcache to achieve efficient data caching and sorting operations in PHP development, and provide specific code examples. What is Memcache? Memcache is
