Application and configuration of the session of PHP memcached

Source: Internet
Author: User
Tags php session php memcached
The use and configuration of the session of PHP memcached

In http://bardo.iteye.com/blog/914110 This article, we have already talked about the installation method of PHP memcached. PHP memcached The use of the session, what are the problems, here briefly:

Memcached's session, the first big advantage is more efficient and faster than the PHP session. Secondly, it is convenient to realize multi-host session sharing
Use the memcached session using the following methods:
A single-site server that can be used in php.ini:
Session.save_handler "Memcached"
Session.save_path? "Host1:11211,host2:11211"
The parameter in the Session.save_path must be a comma separated host name plus port. The host name can also use an IP address.
Although the server is memcached, unlike the memcache extension, it does not need to specify a communication protocol in Save_path
If the server has multiple hosts and you want to give your current virtual host configuration, you can configure it in the. htaccess file. The format is as follows:
Php_value Session.save_handler "memcached"
Php_value Session.save_path? "Host1:11211,host2:11211"
Note: At this point, the value of session.use_cookies in php.ini must be 1. If this value is not 1 in the system, then the

To increase the. htaccess file:
Php_value session.use_cookies = 1
If the. Heaccess error, you can refer to the following example to modify:
# 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 ways to control it directly 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 operating mode, if it is the mod_php way,. htaccess can be modified, but if you install the
fast_cgi, then, you need PHP_FPM to manage the different php.ini. If it's mod_fcgid, then you need to use fcgidinitialenv.

PHPRC "/dirofphiini" to set different php.ini, however, Fcgidinitialenv is the command in the new version. The owner of the book is

Defaultinitenv. Some versions have bugs and are not necessarily set to succeed. For suphp, you also need to specify a different configuration 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 bla bla
# Use same php.ini as mod_php globally for mod_fcgid
Fcgidinitialenv PHPRC "/php"


#httpd-vhost.conf

#using mod_php And/php/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 all of these settings are not working for the site, then you can only use the code to differentiate between the methods.
In the code, one can call Ini_set directly, and the other is to use memcached to write a session class, then, the body

The session function to the session class you write, this is also an example on the Internet, so there is no need to speak 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.