Application and configuration of PHPmemcached sessions

Source: Internet
Author: User
Tags php memcached
The usage and configuration of PHPmemcached sessions are described in the document http://bardo.iteye.com/blog/914110. Use and configuration of PHP memcached Session of PHPmemcached

In the article http://bardo.iteye.com/blog/914110, we have discussed how to install PHP memcached. PHP memcached Session usage:

The first advantage of memcached sessions is that they are more efficient and fast than PHP sessions. Second, it facilitates multi-host session sharing.
Use the memcached session as follows:
A single site server can be used in php. ini:
Session. save_handler "memcached"
Session. save_path? & Quot; host1: 11211, host2: 11211 & quot"
? The parameters in session. save_path must be comma-separated host names and ports. The host name can also use an IP address.
Although the servers are all memcached, unlike memcache extensions, it does not need to specify the communication protocol in save_path.
If the server has multiple hosts and you want to configure your current virtual host, you can configure it in the. htaccess file. The format is as follows:
Php_value session. save_handler "memcached"
Php_value session. save_path? & Quot; host1: 11211, host2: 11211 & quot"
? Note: the value of session. use_cookies in php. ini must be 1. If this value is not 1 in the system

Add the following content to the. htaccess file:
Php_value session. use_cookies = 1
? If the. heaccess error is returned, you can modify it by referring to the following example:
# PHP 4, Apache 1.

? Php_value session. save_handler "memcached"

# PHP 4, Apache 2.

? Php_value session. save_handler "memcached"

# PHP 5, Apache 1 and 2.

? Php_value session. save_handler "memcached"

?. Htaccess can be controlled to the directory level. At the same time, there are other methods that can be directly controlled in php code:
Ini_set ("session. save_handler", "memcached ");
Ini_set ("session. save_path", "host1: 11211, host2: 11211 ");
However, this also depends on your PHP running mode. if it is mod_php,. htaccess can be modified, but if you install
Fast_cgi, so you need php_fpm to manage different php. ini. If it is mod_fcgid, use FcgidInitialEnv

PHPRC "/dirOfPhiIni" to set different php. ini. However, FcgidInitialEnv is a command in the new version. The boss's

DefaultInitEnv. Some versions may have bugs and may not be set successfully. For suPHP, you also need to specify different configurations in its configuration.

Directory.

The following is a configuration instance of mod_fcgid:

# Httpd. conf

LoadModule php5_module/php/php5apache2_2.dll
LoadModule fcgid_module modules/mod_fcgid.so
PHPIniDir/php


# Whatever directives wanted bla
# Use same php. ini as mod_php globally for mod_fcgid
FcgidInitialEnv PHPRC "/php"


# Httpd-vhost.conf

# Using mod_php and/php. ini

??? ServerName php.example.com
??? DocumentRoot "/home/htdocs"

# Using mod_fcgid and/home/user1/php. ini

??? ServerName user1.example.com
??? DocumentRoot "/home/user1/htdocs"
????? FcgidInitialEnv PHPRC "/home/user1"
????? AddHandler fcgid-script. php
????? FcgidWrapper "/php/php-cgi.exe". php

# Using mod_fcgid and/home/user2/php. ini

??? ServerName user2.example.com
??? DocumentRoot "/home/user2/htdocs"
????? FcgidInitialEnv PHPRC "/home/user2"
????? AddHandler fcgid-script. php
????? FcgidWrapper "/php/php-cgi.exe". php

# Using mod_fcgid and global php. ini

??? ServerName user3.example.com
??? DocumentRoot "/home/user3/htdocs"
????? AddHandler fcgid-script. php
????? FcgidWrapper "/php/php-cgi.exe". php
?
If none of these settings work for the site, you can only treat them differently using code.
For use in code, one can directly call ini_set, and the other is to write a session class using memcached, and then reflect

The session function is written into the session class you have written. There are examples on the Internet, so you don't need to talk about it more.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.