CVS update: php4/ext/session

From: Date: Mon, 07 Jun 1999 19:51:55 +0000
Subject: CVS update: php4/ext/session
Groups: php.version4 
Request: Send a blank email to php-version4+get-1384@lists.php.net to get a copy of this message
Date: Monday June 7, 1999 @ 15:51 Author: sas Update of /repository/php4/ext/session In directory php:/tmp/cvs-serv28523 Modified Files: mod_files.c session.c Log Message: better scaling for large servers using many session ids Index: php4/ext/session/mod_files.c diff -u php4/ext/session/mod_files.c:1.3 php4/ext/session/mod_files.c:1.4 --- php4/ext/session/mod_files.c:1.3 Mon Jun 7 12:43:24 1999 +++ php4/ext/session/mod_files.c Mon Jun 7 15:51:52 1999 @@ -41,6 +41,7 @@ int fd; char *lastkey; char *basedir; + int dirdepth; } ps_files; @@ -54,11 +55,16 @@ 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 @@ 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_GC_FUNC(files) { + return SUCCESS; } Index: php4/ext/session/session.c diff -u php4/ext/session/session.c:1.15 php4/ext/session/session.c:1.16 --- php4/ext/session/session.c:1.15 Mon Jun 7 12:43:24 1999 +++ php4/ext/session/session.c Mon Jun 7 15:51:54 1999 @@ -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)

« previous php.version4 (#1384) next »