session_module_name
(PHP 4, PHP 5)
session_module_name — Возвращает и/или устанавливает модуль текущей сессии
Описание
string session_module_name
([ string
$module
] )session_module_name() возвращает название текущего модуля сессии.
Список параметров
-
module
-
Если указан параметр
module
, данный модуль будет использован вместо текущего.
Возвращаемые значения
Возвращает название текущего модуля сессии.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с сессиями
- Управление сессиями
- session_abort
- session_cache_expire
- session_cache_limiter
- session_commit
- session_create_id
- session_decode
- session_destroy
- session_encode
- session_gc
- session_get_cookie_params
- session_id
- session_is_registered
- session_module_name
- session_name
- session_regenerate_id
- session_register_shutdown
- session_register
- session_reset
- session_save_path
- session_set_cookie_params
- session_set_save_handler
- session_start
- session_status
- session_unregister
- session_unset
- session_write_close
Коментарии
This function is used to set the Session Module at site or script level.
The global configuration can be done in php.ini under the [Session] section and with the name of "session.save_handler". The sessions are saved in files by default, like so:
session.save_handler = files
But with this configuration you set one of your websites to use some other session module (if you have them installed and extension loaded with PHP), like so:
<?php
// NOTE: You must use this function before starting session with session_start(); to make it work properly
session_module_name('memcache'); // or pgsql or redis etc
// You'll need to define a save path also, if the module is other than files, like so:
session_save_path('localhost:11211'); // memcache uses port 11211
// or you can use multiple for load balancing:
session_save_path('localhost:11211:41,otherhost:11211:60') // First part is hostname or path to socket, next is port and the last is the weight for that server
//The function also returns the value of the current session module.
echo session_module_name(); // will print memcache in our case
// or maybe a check
if(session_module_name() != 'memcache'){
// Do something, throw an exception maybe
}
was looking for a rather comprehensive list of modules, and found http://stackoverflow.com/questions/8415962/what-exactly-phps-function-session-module-name-is-for but there are more.