1.21. PHP connects to Memcached service

发布时间 : 2025-10-25 13:33:43 UTC      

Page Views: 10 views

In the previous section, we have shown how to install the Memcached service,and then we will show you how PHP uses the Memcached service.

1.21.1. PHP Memcache extension installation

PHP Memcache expansion pack download address: http://pecl.php.net/package/memcache , you can download the latest stable pack (stable).

wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar -zxvf memcache-2.2.7.tgz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

Note: /usr/local/php/ for php the installation path needs to be adjusted according to the actual directory of your installation.

You will be displayed after the installation is successful memcache.so Expanded location, such as mine:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

Finally, we need to add this extension to the php , open yours php.ini add the following at the end of the file:

[Memcache]
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
extension = memcache.so

Restart after adding php I am using the nginx+php-fpm process, so the command is as follows:

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

If it is apache use the following command:

/usr/local/apache2/bin/apachectl restart

Check the installation result

/usr/local/php/bin/php -m | grep memcache

If the installation is successful, it will output: memcache .

Or access it through a browser phpinfo() function, as shown in the following figure:

image0

1.21.2. PHP connection Memcached

connect('localhost', 11211) or die ("Could not connect"); //Connect to Memcached server
$memcache->set('key', 'test');        //Set a variable to memory with the name key and the value test
$get_value = $memcache->get('key');   //Retrieve the value of the key from memory
echo $get_value;
?>

For more PHP operations Memcached, please see: http://php.net/manual/zh/book.memcache.php

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。