PHP _php tutorial for implementing NFS sharing with multi-server session sharing

Source: Internet
Author: User
PHP enables NFS sharing for multi-server session sharing
In the preface, the problem of multi-server sharing is presented by the NIO Warrior, and the original data of the server sharing session with PHP is shown.

One way is to use NFS to share the session, if the session volume is larger and all of the session files are in the same subdirectory, then it can cause a serious load problem, and even make the site unusable. This article is to do a detailed explanation of the scheme.
First, modify the Session.save_path option for php.ini, which is roughly the following:

Session.save_path = "2;/tmp/php_sess"

The session is stored in the "/tmp/php_sess" directory and is divided into 2 levels of subdirectories, each of which has 16 subdirectories respectively.
Next, assuming that PHP's home directory is/usr/local/server/php/, create a new file/usr/local/server/php/include/php/ext/session/mod_files.sh with the following contents:

#! /bin/sh
# NAME
# Mod_files.sh-update of the php-source/ext/session/mod_files.sh
#
# Synopsis
# mod_files.sh Basedir Depth [numberofsubdirs]
#
# DESCRIPTION
# This script creates the directories tree used by PHP to store the session files
# (see php.ini-' session.save_path ' option)
#
# Example:if want PHP to store the session files in a directory tree
# of 3 levels of depth containing directories in each directory,
# First, put the setting bellow in the php.ini file:
#
# Session.save_path = "3;/tmp/session"
#
# now create the Basedir directory: ' Mkdir/tmp/session '
#
# Then, call this scrip with the following arguments:
#
#./mod_files.sh./mod_files.sh/tmp/session 3 32

if test "$" = ""; Then
echo "Usage: $ basedir depth [numberofsubdirs]"
echo "Numberofsubdirs:if unset, defaults to 16. If, Subdirs, if, Subdirs. "
Exit 1
Fi

if test "$" = "0"; Then
Exit 0
Fi

hash_chars= "0 1 2 3 4 5 6 7 8 9 a B c D E F"
if [!-Z $]; Then
if test "$"-a "$"-eq "32"; Then
hash_chars= "$hash _chars G h i j k l m n o p q R S t u V"
if test "$ 64"-eq "; Then
Hash_chars= "$hash _chars w x y z A B C D E F G H I J K L M N O P Q R S T U V w x y z-,"
Fi
Fi
Fi

For i in $hash _chars; Do
Newpath= "$1/$i"
mkdir $newpath | | Exit 1
SH $ $newpath ' expr $2-1 ' $
Done

Once set to executable, run the following command to create the hash directory:

Shell> #cd/usr/local/server/php/include/php/ext/session/
Shell>#./mod_files.sh/tmp/php_sess 2 16

The NFS share is now set to start. Assume that there are 3 hosts, the IP is 192.168.0.1 (hostname svr1), 192.168.0.2 (hostname svr2), 192.168.0.3 (hostname svr3), now let 192.168.0.1来 provides NFS shared services, configuration/etc/ Exports, add the following:

/tmp/php_sess/svr* (Rw,no_root_squash)

Then restart the NFS service to provide NFS sharing for the other two hosts.
On SVR2, SVR3 execute the following command to Hang on NFS:

Shell> #mkdir/tmp/php_sess
Shell> #mount svr1:/tmp/php_sess/tmp/php_sess

Finally, add/modify the above mentioned content on the two hosts, and then restart Apache on the php.ini.

http://www.bkjia.com/PHPjc/317987.html www.bkjia.com true http://www.bkjia.com/PHPjc/317987.html techarticle PHP Implementation of multi-server Session sharing NFS sharing foreword, the NIO Warrior has proposed the session multi-server sharing problem, the original text please see PHP realizes the multi-server sharing session data. Among them, there is a kind of ...

  • 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.