Re: [PHP4BETA] Re: yet another Session oddness/bug?

From: Date: Wed, 29 Mar 2000 20:43:43 +0000
Subject: Re: [PHP4BETA] Re: yet another Session oddness/bug?
References: 1 2 3 4  Groups: php.version4 
Request: Send a blank email to php-version4+get-12833@lists.php.net to get a copy of this message
On Wed, Mar 29, 2000 at 01:17:07PM -0800, waltb wrote: > Sascha Schumann wrote: > > > On Wed, Mar 29, 2000 at 11:29:59AM -0800, waltb wrote: > > > Hi Peter, > > > I have included my test app. Its pretty straight forward. > > > To compile it just do > > > gcc -o test test.c -lpthread > > > > Are you seeing any messages in Apache's error.log? > > > > I've seen a few (3 or 4) segfaults for Apache, but other then > that it seems to be ok. > I'm currently running a test using 4 machines, each with 200 threads > doing 200 calls to the same script, and I'm getting no apache errors. > I've noticed that there seems to be 3 recurring problems with sessions > under > a load. I've tested using the files method as well as mm method of > session handlers > under linux using apache 1.3.12. > > 1) The very first time the test app calls the script the session is > created, > and apache sends me back the Set-Cookie: PHPSESSID=blah. > The next request to the same page seems to fail. The test for > !isset($count) > falls through and the script re-registers the count variable. It should > already > be set, because session_start() was called. > > <? > session_start(); > ?> > <html> > <? > if (!isset($count)) > { > session_register("count"); > $count = 1; > echo "\nNEW SESSION\n"; > } > else > $count++; > ?> > COUNT=<? echo $count; ?>;<br> > </html> > > 2) During a test, the value of the session variable > seems to get assigned some random value. So > request # 25 returns a response with COUNT=25, > but the ver next request #26, the COUNT=2. > > 3) This one could be related to other problems, but > I have seen cases where I get multiple lines of > errors in the php error logs. > [30-Mar-2000 03:52:54] PHP Warning: Failed to write session data. > Please check that the current setting of session.save_path is correct > (/tmp) in Unknown on line 0 > [30-Mar-2000 03:52:54] PHP Warning: Failed to write session data. > Please check that the current setting of session.save_path is correct > (/tmp) in Unknown on line 0 > [30-Mar-2000 03:52:55] PHP Warning: Failed to write session data. > Please check that the current setting of session.save_path is correct > (/tmp) in Unknown on line 0 > [30-Mar-2000 03:52:55] PHP Warning: Failed to write session data. > Please check that the current setting of session.save_path is correct > (/tmp) in Unknown on line 0 I've just committed a few changes which should detail why these error messages have been emitted. If you are running 4.0RC1, please apply the attached patch. > I would really like to be able to rely on sessions, but the site I'm > working on is most likely going to have a LOT of traffic, > so I need it to be stable. If there is anything I can do to help with > testing/debugging please let me know. - Sascha

Index: mod_files.c =================================================================== RCS file: /repository/php4/ext/session/mod_files.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- mod_files.c 2000/02/19 23:41:19 1.27 +++ mod_files.c 2000/03/29 20:37:12 1.28 @@ -145,19 +145,26 @@ if (data->fd != -1) flock(data->fd, LOCK_EX); #endif + + if (data->fd == -1) + php_error(E_WARNING, "open(%s, O_RDWR) failed: %m (%d)", buf, errno); } } -static void _ps_files_cleanup_dir(const char *dirname, int maxlifetime) +static int _ps_files_cleanup_dir(const char *dirname, int maxlifetime) { DIR *dir; struct dirent *entry; struct stat sbuf; char buf[MAXPATHLEN]; time_t now; + int nrdels = 0; dir = opendir(dirname); - if (!dir) return; + if (!dir) { + php_error(E_NOTICE, "_ps_files_cleanup_dir: opendir(%s) failed: %m (%d)\n", dirname, errno); + return (0); + } time(&now); @@ -172,10 +179,13 @@ /* is it expired? */ (now - sbuf.st_atime) > maxlifetime) { unlink(buf); + nrdels++; } } closedir(dir); + + return (nrdels); } #define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA() @@ -277,7 +287,7 @@ an external entity (i.e. find -ctime x | xargs rm) */ if (data->dirdepth == 0) - _ps_files_cleanup_dir(data->basedir, maxlifetime); + *nrdels = _ps_files_cleanup_dir(data->basedir, maxlifetime); return SUCCESS; } Index: mod_mm.c =================================================================== RCS file: /repository/php4/ext/session/mod_mm.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- mod_mm.c 2000/02/19 23:41:19 1.6 +++ mod_mm.c 2000/03/29 20:37:29 1.7 @@ -305,6 +305,7 @@ time_t now; ps_sd *sd, *next; + *nrdels = 0; ps_mm_debug("gc\n"); mm_lock(data->mm, MM_LOCK_RW); @@ -315,8 +316,10 @@ for (sd = data->hash[h]; sd; sd = next) { next = sd->next; ps_mm_debug("looking at %s\n", sd->key); - if ((now - sd->ctime) > maxlifetime) + if ((now - sd->ctime) > maxlifetime) { ps_sd_destroy(data, sd); + *nrdels++; + } } mm_unlock(data->mm); Index: php_session.h =================================================================== RCS file: /repository/php4/ext/session/php_session.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- php_session.h 2000/03/13 15:49:13 1.28 +++ php_session.h 2000/03/29 20:37:29 1.29 @@ -35,7 +35,7 @@ #define PS_READ_ARGS void **mod_data, const char *key, char **val, int *vallen #define PS_WRITE_ARGS void **mod_data, const char *key, const char *val, const int vallen #define PS_DESTROY_ARGS void **mod_data, const char *key -#define PS_GC_ARGS void **mod_data, int maxlifetime +#define PS_GC_ARGS void **mod_data, int maxlifetime, int *nrdels typedef struct ps_module_struct { const char *name; Index: session.c =================================================================== RCS file: /repository/php4/ext/session/session.c,v retrieving revision 1.119 retrieving revision 1.122 diff -u -r1.119 -r1.122 --- session.c 2000/03/26 00:43:56 1.119 +++ session.c 2000/03/29 20:37:29 1.122 @@ -36,6 +36,7 @@ #include "ext/standard/datetime.h" #include "ext/standard/php_lcg.h" #include "ext/standard/url_scanner.h" +#include "ext/standard/php_output.h" #include "ext/standard/php_rand.h" /* for RAND_MAX */ #ifdef ZTS @@ -122,7 +123,7 @@ void (*func)(PSLS_D); } php_session_cache_limiter; -#define CACHE_LIMITER_FUNC(name) void _php_cache_limiter_##name(PSLS_D) +#define CACHE_LIMITER_FUNC(name) static void _php_cache_limiter_##name(PSLS_D) #define CACHE_LIMITER(name) { #name, _php_cache_limiter_##name }, #define ADD_COOKIE(a) sapi_add_header(estrdup(a), strlen(a)); @@ -554,7 +555,15 @@ SLS_FETCH(); if (SG(headers_sent)) { - php_error(E_WARNING, "Cannot send session cache limiter - headers already sent"); + char *output_start_filename = php_get_output_start_filename(); + int output_start_lineno = php_get_output_start_lineno(); + + if (output_start_filename) { + php_error(E_WARNING, "Cannot send session cache limiter - headers already sent by (output started at %s:%d)", + output_start_filename, output_start_lineno); + } else { + php_error(E_WARNING, "Cannot send session cache limiter - headers already sent"); + } return; } @@ -581,7 +590,15 @@ SLS_FETCH(); if (SG(headers_sent)) { - php_error(E_WARNING, "Cannot send session cookie - headers already sent"); + char *output_start_filename = php_get_output_start_filename(); + int output_start_lineno = php_get_output_start_lineno(); + + if (output_start_filename) { + php_error(E_WARNING, "Cannot send session cookie - headers already sent by (output started at %s:%d)", + output_start_filename, output_start_lineno); + } else { + php_error(E_WARNING, "Cannot send session cookie - headers already sent"); + } return; } @@ -796,10 +813,15 @@ _php_session_initialize(PSLS_C); if (PS(mod_data) && PS(gc_probability) > 0) { + int nrdels = -1; + srand(time(NULL)); nrand = (int) (100.0*rand()/RAND_MAX); - if (nrand < PS(gc_probability)) - PS(mod)->gc(&PS(mod_data), PS(gc_maxlifetime)); + if (nrand < PS(gc_probability)) { + PS(mod)->gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels); + if (nrdels != -1) + php_error(E_NOTICE, "Session gc: cleared %d\n", nrdels); + } } }
« previous php.version4 (#12833) next »