PHP saves the session to the memcache server

Source: Internet
Author: User
PHP saves the session to the memcache server. the traditional session is written to the server file. you can see in php. ini that the list is as follows:

[Plain]View plaincopy

  • Session. save_handler = files

  • Session. save_path = "sess save path"


  • However, if there are many website users, session access will inevitably affect the website speed. Because the file reading speed is very low.

    As we all know, memcache, as a memory cache server, uses a hash algorithm to read data in the form of key-> value, which is much faster than reading files.

    The configuration for saving the session to the memcache server is as follows:

    Method 1:

    Open the php. ini file and modify the following two parameters:

    [Plain]View plaincopy

  • Session. save_handler = memcache

  • Session. save_path = "tcp: // Mem server 1: port number, tcp: // Mem Server 2: port number ..."


  • Method 2:

    Use the ini_set function in the php file for configuration. this method solves the php configuration problem of the shared server.

    [Php]View plaincopy

  • ....

  • Ini_set ("session. save_handler", "memcache ");

  • Ini_set ("session. save_path", "tcp: // Mem server 1: port number, tcp: // Mem Server 2: port number ...");

  • ....

  • ?>


  • Restart the Web server!

    In this case, the session will not be saved as a file, but will be saved to the Memcache server. the key to be saved is session_id.

    Telnet to the memcache server for get View

    Telnet memcache server port number

    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.