mirror of
https://github.com/php/php-src.git
synced 2024-12-02 06:13:40 +08:00
better scaling for large servers using many session ids
This commit is contained in:
parent
bc1e4a5a10
commit
4b023c157a
@ -41,6 +41,7 @@ typedef struct {
|
||||
int fd;
|
||||
char *lastkey;
|
||||
char *basedir;
|
||||
int dirdepth;
|
||||
} ps_files;
|
||||
|
||||
|
||||
@ -54,11 +55,16 @@ ps_module ps_mod_files = {
|
||||
PS_OPEN_FUNC(files)
|
||||
{
|
||||
ps_files *data;
|
||||
char *p;
|
||||
|
||||
data = ecalloc(sizeof(*data), 1);
|
||||
*mod_data = data;
|
||||
|
||||
data->fd = -1;
|
||||
if((p = strchr(save_path, ':'))) {
|
||||
data->dirdepth = strtol(save_path, NULL, 10);
|
||||
save_path = p + 1;
|
||||
}
|
||||
data->basedir = estrdup(save_path);
|
||||
|
||||
return SUCCESS;
|
||||
@ -77,17 +83,38 @@ PS_CLOSE_FUNC(files)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
#if WIN32|WINNT
|
||||
#define DIR_DELIMITER '\\'
|
||||
#else
|
||||
#define DIR_DELIMITER '/'
|
||||
#endif
|
||||
|
||||
static void _ps_files_open(ps_files *data, const char *key)
|
||||
{
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
const char *p;
|
||||
int i;
|
||||
int n;
|
||||
int keylen;
|
||||
|
||||
if(data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) {
|
||||
if(data->lastkey) efree(data->lastkey);
|
||||
if(data->fd > -1) close(data->fd);
|
||||
|
||||
keylen = strlen(key);
|
||||
if(keylen <= data->dirdepth || MAXPATHLEN <
|
||||
(strlen(data->basedir) + 2 * data->dirdepth + keylen + 5))
|
||||
return;
|
||||
p = key;
|
||||
n = sprintf(buf, "%s/", data->basedir);
|
||||
for(i = 0; i < data->dirdepth; i++) {
|
||||
buf[n++] = *p++;
|
||||
buf[n++] = DIR_DELIMITER;
|
||||
}
|
||||
strcat(buf, p);
|
||||
|
||||
data->lastkey = estrdup(key);
|
||||
|
||||
snprintf(buf, MAXPATHLEN, "%s/%s", data->basedir, key);
|
||||
data->fd = open(buf, O_CREAT | O_RDWR, 0600);
|
||||
if(data->fd > -1) {
|
||||
flock(data->fd, LOCK_EX);
|
||||
@ -151,5 +178,6 @@ PS_DELETE_FUNC(files)
|
||||
|
||||
PS_GC_FUNC(files)
|
||||
{
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -31,9 +31,7 @@
|
||||
* TODO:
|
||||
* - improve session id creation to avoid collisions
|
||||
* (make use of mersenne twister, other data such as IP, browser etc.)
|
||||
* - improve files handler for better scaling
|
||||
* - add complete support for objects (partially implemented)
|
||||
* - complete ZTS support (currently only useable as non-ZTS)
|
||||
* - userland callback functions for ps_module
|
||||
*/
|
||||
#if !(WIN32|WINNT)
|
||||
|
Loading…
Reference in New Issue
Block a user