Basant Kukreja
In memory session extension for multithreaded php
Php's default session handler (mod_files) saves the session data in file. To improve performance, we can save the session data in ramdisk or in /tmp/ on Solaris. Even when we store the session data in ramdisk there is lot of CPU cycles are spent in open/read/write call. So the question is can we improve the session writing/reading in php.
Answer is yes. If we have memory available in the system then session can be stored in RAM. If php is compiled without threads (e.g fastcgi) then mod_mm extension is there in php which does the job. It saves the session in mmap. But when we run php in multithreaded mode and entire php is inside single process then session can be allocated in process memory. I wrote a php extension for multithreaded php which saves php session in memory.
Php's session GC will cleanup the old sessions. So session gc time session.gc_maxlifetime should not be very high otherwise it will consume lots of memory.
Sources can be downloaded from :
svn co http://svn.php.net/repository/pecl/memsession
Sources can be viewed from here. Look for README for more information.
Compilation is similar to any other extension:
Compiling on unix platforms (for mulithreaded php e.g NSAPI php)
$ phpize
$ CFLAGS="-m32" ./configure --with-php-config=<phpinstdir>/bin/php-config
$ gmake
$ gmake install
Compiling in Windows (tested on Win2K and Windows Vista):
C:\php-src-5.3.0> cscript /nologo configure.js --enable-apache2handler --enable-zts --enable-memsession=shared
C:\php-src-5.3.0> nmake
Configuration (php.ini) :
extension="memession.so"
[Session]
session.save_handler=memsession
GCC notes : Since memsession uses gcc's atomic operation which was added in 4.1.2 so gcc version 4.1.2 is required. "-march=i586" might be required to enable gcc's atomic operations.
Posted at 04:21PM Sep 04, 2009 by Basant Kukreja in php | Comments[0]
Comments:
Friday Sep 04, 2009