How to store PHP sessions in APC Cache?

2020-05-18 07:35发布

Storing sessions in disk very slow and painful for me. I'm having very high traffic. I want to store session in Advanced PHP Cache, how can I do this?

9条回答
Lonely孤独者°
2楼-- · 2020-05-18 07:52

You can store your session data within PHP internals shared memory.

session.save_handler = mm

But it needs to be available: http://php.net/manual/en/session.installation.php

查看更多
ゆ 、 Hurt°
3楼-- · 2020-05-18 07:58

Caching external data in PHP

Tutorial Link - http://www.gayadesign.com/diy/caching-external-data-in-php/


How to Use APC Caching with PHP

Tutorial Link - http://www.script-tutorials.com/how-to-use-apc-caching-with-php/

查看更多
冷血范
4楼-- · 2020-05-18 08:02

Another good solution is to store PHP sessions in memcached

session.save_handler = memcache

查看更多
相关推荐>>
5楼-- · 2020-05-18 08:03

Explicit Session Closing immediately following Session Starting, Opening and Writing should solve the locking problem in Unirgy's Answer(where session access is always cyclic(start/open-write-close). I also Imagine a Second class - APC_journaling or something similar used in conjunction with Sessions would be ultimately better.... A session starts and is written to with a unique external Id assigned to each session, that session is closed, and a journal (array in apc cache via _store & _add) is opened/created for any other writes intended to go to session which can then be read, validated and written to the session(identified by that unique id!) in apc at the next convenient opportunity.

I found a good blog post Explaining that the Locking havoc Sven refers to comes from the Session blocking until it's closed or script execution ends. The session being immediately closed doesn't prevent reading just writing. http://konrness.com/php5/how-to-prevent-blocking-php-requests - link to the blog post. Hope this helps.

查看更多
Fickle 薄情
6楼-- · 2020-05-18 08:08

Store it in cookies (encrypted) or MongoDB. APC isn't really intended for that purpose.

查看更多
▲ chillily
7楼-- · 2020-05-18 08:11

Simply putting your /tmp disk (or, wherever PHP session files are stored) onto a RAM disk such as tmpfs or ramfs would also have serious performance gains, and would be a much more transparent switch, with zero code changes.

The performance gain may be significantly less, but it will still be significantly faster than on-disk sessions.

查看更多
登录 后发表回答