Memcache stores PHP sessions

Source: Internet
Author: User

In PECL: Package: memcache 2.1.1, changelog contains one of the following:

-Added experimental session storage support. You can use memcached as session storage.

That is, you can directly use memcache for PHP session. save_handler.

1. Install memcached, or the set./configure; Make; make install. Note that memcached uses libevent as the event driver, so install libevent first.

2. Install PECL: memcache and install it using the PECL command line tool:

pecl install memcache

Or install it directly from the source code:

phpize
./configure
make
make install

Open extension = memcache. So in PHP. ini and restart Apache. Check that registered save handlers in phpinfo has three files user memcache available.

3. modify the configuration file and set it globally in PHP. ini:

session.save_handler = memcache
session.save_path = tcp://127.0.0.1:11211

Or. htaccess in a directory:

php_value session.save_handler memcache
php_value session.save_path tcp://127.0.0.1:11211

Or in an application:

ini_set(session.save_handler, memcache);
ini_set(session.save_path, tcp://127.0.0.1:11211); 

Multiple memcached servers are separated by commas (,). They are the same as those described in the memcache: addserver () document. They can contain additional parameters such as persistent, weight, timeout, and retry_interval, for example: TCP: // host1: port1? Persistent = 1 & Weight = 2, TCP: // host2: port2.

4. Start memcached:

memcached -d -l 127.0.0.1 -p 11212 -m 128

5. Apply memcache in the program for session storage. Use an example to test it:

<? PHP
Session_start ();
If (! Isset (

In PECL: Package: memcache 2.1.1, changelog contains one of the following:

-Added experimental session storage support. You can use memcached as session storage.

That is, you can directly use memcache for PHP session. save_handler.

1. Install memcached, or the set./configure; Make; make install. Note that memcached uses libevent as the event driver, so install libevent first.

2. Install PECL: memcache and install it using the PECL command line tool:

pecl install memcache

Or install it directly from the source code:

phpize
./configure
make
make install

Open extension = memcache. So in PHP. ini and restart Apache. Check that registered save handlers in phpinfo has three files user memcache available.

3. modify the configuration file and set it globally in PHP. ini:

session.save_handler = memcache
session.save_path = tcp://127.0.0.1:11211

Or. htaccess in a directory:

php_value session.save_handler memcache
php_value session.save_path tcp://127.0.0.1:11211

Or in an application:

ini_set(session.save_handler, memcache);
ini_set(session.save_path, tcp://127.0.0.1:11211); 

Multiple memcached servers are separated by commas (,). They are the same as those described in the memcache: addserver () document. They can contain additional parameters such as persistent, weight, timeout, and retry_interval, for example: TCP: // host1: port1? Persistent = 1 & Weight = 2, TCP: // host2: port2.

4. Start memcached:

memcached -d -l 127.0.0.1 -p 11212 -m 128

5. Apply memcache in the program for session storage. Use an example to test it:

___FCKpd___6

6. Use sessionid to query in memcached:

<?php
$memcache = memcache_connect(localhost, 11211);
var_dump($memcache->get(19216821213c65cedec65b0883238c278eeb573e077));
?>

You will see

string(37) TEST|i:1177556731;TEST3|i:1177556881;

This output proves that the session works normally.

Using memcache to store sessions is much faster in reading and writing than when using files, and it is more convenient for multiple servers to share sessions, you can configure these servers to apply the same group of memcached servers, reducing the additional workload. The disadvantage is that session data is stored in memory, which lacks persistence, but it is not a big problem for session data.

In addition, WS memcached session handler for PHP provides a method to use session_set_save_handler to apply memcached.

Session [test]) {

In PECL: Package: memcache 2.1.1, changelog contains one of the following:

-Added experimental session storage support. You can use memcached as session storage.

That is, you can directly use memcache for PHP session. save_handler.

1. Install memcached, or the set./configure; Make; make install. Note that memcached uses libevent as the event driver, so install libevent first.

2. Install PECL: memcache and install it using the PECL command line tool:

pecl install memcache

Or install it directly from the source code:

phpize
./configure
make
make install

Open extension = memcache. So in PHP. ini and restart Apache. Check that registered save handlers in phpinfo has three files user memcache available.

3. modify the configuration file and set it globally in PHP. ini:

session.save_handler = memcache
session.save_path = tcp://127.0.0.1:11211

Or. htaccess in a directory:

php_value session.save_handler memcache
php_value session.save_path tcp://127.0.0.1:11211

Or in an application:

ini_set(session.save_handler, memcache);
ini_set(session.save_path, tcp://127.0.0.1:11211); 

Multiple memcached servers are separated by commas (,). They are the same as those described in the memcache: addserver () document. They can contain additional parameters such as persistent, weight, timeout, and retry_interval, for example: TCP: // host1: port1? Persistent = 1 & Weight = 2, TCP: // host2: port2.

4. Start memcached:

memcached -d -l 127.0.0.1 -p 11212 -m 128

5. Apply memcache in the program for session storage. Use an example to test it:

___FCKpd___6

6. Use sessionid to query in memcached:

___FCKpd___7

You will see

___FCKpd___8

This output proves that the session works normally.

Using memcache to store sessions is much faster in reading and writing than when using files, and it is more convenient for multiple servers to share sessions, you can configure these servers to apply the same group of memcached servers, reducing the additional workload. The disadvantage is that session data is stored in memory, which lacks persistence, but it is not a big problem for session data.

In addition, WS memcached session handler for PHP provides a method to use session_set_save_handler to apply memcached.

Session [test] = Time ();
}

In PECL: Package: memcache 2.1.1, changelog contains one of the following:

-Added experimental session storage support. You can use memcached as session storage.

That is, you can directly use memcache for PHP session. save_handler.

1. Install memcached, or the set./configure; Make; make install. Note that memcached uses libevent as the event driver, so install libevent first.

2. Install PECL: memcache and install it using the PECL command line tool:

pecl install memcache

Or install it directly from the source code:

phpize
./configure
make
make install

Open extension = memcache. So in PHP. ini and restart Apache. Check that registered save handlers in phpinfo has three files user memcache available.

3. modify the configuration file and set it globally in PHP. ini:

session.save_handler = memcache
session.save_path = tcp://127.0.0.1:11211

Or. htaccess in a directory:

php_value session.save_handler memcache
php_value session.save_path tcp://127.0.0.1:11211

Or in an application:

ini_set(session.save_handler, memcache);
ini_set(session.save_path, tcp://127.0.0.1:11211); 

Multiple memcached servers are separated by commas (,). They are the same as those described in the memcache: addserver () document. They can contain additional parameters such as persistent, weight, timeout, and retry_interval, for example: TCP: // host1: port1? Persistent = 1 & Weight = 2, TCP: // host2: port2.

4. Start memcached:

memcached -d -l 127.0.0.1 -p 11212 -m 128

5. Apply memcache in the program for session storage. Use an example to test it:

___FCKpd___6

6. Use sessionid to query in memcached:

___FCKpd___7

You will see

___FCKpd___8

This output proves that the session works normally.

Using memcache to store sessions is much faster in reading and writing than when using files, and it is more convenient for multiple servers to share sessions, you can configure these servers to apply the same group of memcached servers, reducing the additional workload. The disadvantage is that session data is stored in memory, which lacks persistence, but it is not a big problem for session data.

In addition, WS memcached session handler for PHP provides a method to use session_set_save_handler to apply memcached.

Session [test3] = Time ();

Print

In PECL: Package: memcache 2.1.1, changelog contains one of the following:

-Added experimental session storage support. You can use memcached as session storage.

That is, you can directly use memcache for PHP session. save_handler.

1. Install memcached, or the set./configure; Make; make install. Note that memcached uses libevent as the event driver, so install libevent first.

2. Install PECL: memcache and install it using the PECL command line tool:

pecl install memcache

Or install it directly from the source code:

phpize
./configure
make
make install

Open extension = memcache. So in PHP. ini and restart Apache. Check that registered save handlers in phpinfo has three files user memcache available.

3. modify the configuration file and set it globally in PHP. ini:

session.save_handler = memcache
session.save_path = tcp://127.0.0.1:11211

Or. htaccess in a directory:

php_value session.save_handler memcache
php_value session.save_path tcp://127.0.0.1:11211

Or in an application:

ini_set(session.save_handler, memcache);
ini_set(session.save_path, tcp://127.0.0.1:11211); 

Multiple memcached servers are separated by commas (,). They are the same as those described in the memcache: addserver () document. They can contain additional parameters such as persistent, weight, timeout, and retry_interval, for example: TCP: // host1: port1? Persistent = 1 & Weight = 2, TCP: // host2: port2.

4. Start memcached:

memcached -d -l 127.0.0.1 -p 11212 -m 128

5. Apply memcache in the program for session storage. Use an example to test it:

___FCKpd___6

6. Use sessionid to query in memcached:

___FCKpd___7

You will see

___FCKpd___8

This output proves that the session works normally.

Using memcache to store sessions is much faster in reading and writing than when using files, and it is more convenient for multiple servers to share sessions, you can configure these servers to apply the same group of memcached servers, reducing the additional workload. The disadvantage is that session data is stored in memory, which lacks persistence, but it is not a big problem for session data.

In addition, WS memcached session handler for PHP provides a method to use session_set_save_handler to apply memcached.

Session [test];
Print <br>;
Print

In PECL: Package: memcache 2.1.1, changelog contains one of the following:

-Added experimental session storage support. You can use memcached as session storage.

That is, you can directly use memcache for PHP session. save_handler.

1. Install memcached, or the set./configure; Make; make install. Note that memcached uses libevent as the event driver, so install libevent first.

2. Install PECL: memcache and install it using the PECL command line tool:

pecl install memcache

Or install it directly from the source code:

phpize
./configure
make
make install

Open extension = memcache. So in PHP. ini and restart Apache. Check that registered save handlers in phpinfo has three files user memcache available.

3. modify the configuration file and set it globally in PHP. ini:

session.save_handler = memcache
session.save_path = tcp://127.0.0.1:11211

Or. htaccess in a directory:

php_value session.save_handler memcache
php_value session.save_path tcp://127.0.0.1:11211

Or in an application:

ini_set(session.save_handler, memcache);
ini_set(session.save_path, tcp://127.0.0.1:11211); 

Multiple memcached servers are separated by commas (,). They are the same as those described in the memcache: addserver () document. They can contain additional parameters such as persistent, weight, timeout, and retry_interval, for example: TCP: // host1: port1? Persistent = 1 & Weight = 2, TCP: // host2: port2.

4. Start memcached:

memcached -d -l 127.0.0.1 -p 11212 -m 128

5. Apply memcache in the program for session storage. Use an example to test it:

___FCKpd___6

6. Use sessionid to query in memcached:

___FCKpd___7

You will see

___FCKpd___8

This output proves that the session works normally.

Using memcache to store sessions is much faster in reading and writing than when using files, and it is more convenient for multiple servers to share sessions, you can configure these servers to apply the same group of memcached servers, reducing the additional workload. The disadvantage is that session data is stored in memory, which lacks persistence, but it is not a big problem for session data.

In addition, WS memcached session handler for PHP provides a method to use session_set_save_handler to apply memcached.

Session [test3];
Print <br>;
Print session_id ();
?>

6. Use sessionid to query in memcached:

___FCKpd___7

You will see

___FCKpd___8

This output proves that the session works normally.

Using memcache to store sessions is much faster in reading and writing than when using files, and it is more convenient for multiple servers to share sessions, you can configure these servers to apply the same group of memcached servers, reducing the additional workload. The disadvantage is that session data is stored in memory, which lacks persistence, but it is not a big problem for session data.

In addition, WS memcached session handler for PHP provides a method to use session_set_save_handler to apply memcached.

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.