RAM is faster than disk. If you have enough RAM, it is a good idea to keep server session files in RAM to improve performance. All session contents will be removed when you restart Apache with php_mod.
Save to RAM Disk
Use RAM disk to replace hard drive is the easiest way is to improve session management performance.
You may create RAM disk in Linux with following command:
mkdir /tmp/ramdisk chmod 777 /tmp/ramdisk mount -t tmpfs -o size=512M tmpfs /tmp/ramdisk/
If you are uncomfortable with 777, please read PHP doesn’t have permissions of session file [duplicate] on StackOverflow and change according to how you run PHP programs.
Then Modify session.save_path in php.ini to your RAM disk as below and restart your apache.
session.save_path="/tmp/ramdisk"
PHP Shared Memory
Before you enable this feature, you need to make sure you PHP is compiler with the –with-mm option. Check the Installation and Configuration in PHP manual to compile for your operating system.
If succeed, modify session.save_handler in php.ini from file to mm as below and restart your apache. You may see more in How Sessions Are Support in PHP? by Dr. Hrgong Yang.
session.save_handler = mm
You need to use wincache in Windows according to WinCache Session Handler. mm is not available on PHP for Windows.
Reference
- StackOverflow: How to store PHP sessions in APC Cache?
- BitrixSoft: Configuring Web Systems For Best Performance: PHP Performance
- 海豹雜記:在 Linux 上使用 RAM Disk 提高資料讀寫速度
- nixCraft: Linux RAM Disk: Creating A Filesystem In RAM
- StackOverflow: PHP doesn’t have permissions of session file [duplicate]
- PHP: PHP Manual: Appendices: php.ini directives
- PHP: PHP Manual: Runtime Configuration: session.save_path
- PHP: PHP Manual: Installation and Configuration
- PHP: PHP Manual: Runtime Configuration: session.save_handler
- PHP Tutorials – Herong’s Tutorial Examples: How Sessions Are Support in PHP?
- PHP: PHP Manual: WinCache: WinCache Session Handler
This is a nice simple tutorial. Thank you for taking the time to write it. The only thing I see missing is how to add an entry to /etc/fstab so this persists a reboot.
LikeLiked by 1 person
Hi TwitchCaptain,
Thanks for your hint. I didn’t notice it. It would be great if you could kindly share a mini-how-to. I will put a link to your post to help others.
Best regards,
Amigo
LikeLike