@@ -277,7 +277,7 @@ PS_OPEN_FUNC(memcached)
277277PS_CLOSE_FUNC (memcached )
278278{
279279 memcached_sess * memc_sess = PS_GET_MOD_DATA ();
280-
280+
281281 if (!memc_sess ) {
282282 php_error_docref (NULL TSRMLS_CC , E_WARNING , "Session is not allocated, check session.save_path value" );
283283 return FAILURE ;
@@ -336,8 +336,9 @@ PS_READ_FUNC(memcached)
336336 * val = zend_string_init (payload , payload_len , 1 );
337337 free (payload );
338338 return SUCCESS ;
339- } else if (status = MEMCACHED_NOTFOUND ) {
339+ } else if (status == MEMCACHED_NOTFOUND ) {
340340 * val = ZSTR_EMPTY_ALLOC ();
341+ return SUCCESS ;
341342 } else {
342343 return FAILURE ;
343344 }
@@ -351,7 +352,7 @@ PS_WRITE_FUNC(memcached)
351352 memcached_return status ;
352353 memcached_sess * memc_sess = PS_GET_MOD_DATA ();
353354 size_t key_length ;
354-
355+
355356 if (!memc_sess ) {
356357 php_error_docref (NULL TSRMLS_CC , E_WARNING , "Session is not allocated, check session.save_path value" );
357358 return FAILURE ;
@@ -409,39 +410,34 @@ PS_GC_FUNC(memcached)
409410PS_CREATE_SID_FUNC (memcached )
410411{
411412 zend_string * sid ;
412- int maxfail = 3 ;
413+ int retries = 3 ;
413414 memcached_sess * memc_sess = PS_GET_MOD_DATA ();
415+ time_t expiration = PS (gc_maxlifetime );
414416
415- do {
417+ if (!memc_sess ) {
418+ return NULL ;
419+ }
420+
421+ while (retries -- > 0 ) {
416422 sid = php_session_create_id ((void * * )& memc_sess );
417- if (!sid ) {
418- if (-- maxfail < 0 ) {
419- return NULL ;
420- } else {
421- continue ;
423+
424+ if (sid ) {
425+ if (memcached_add (memc_sess -> memc_sess , sid -> val , sid -> len , "0" , 0 , expiration , 0 ) == MEMCACHED_SUCCESS ) {
426+ return sid ;
422427 }
423- }
424- /* Check collision */
425- /* FIXME: mod_data(memc_sess) should not be NULL (User handler could be NULL) */
426- if (memc_sess && memcached_exist (memc_sess -> memc_sess , sid -> val , sid -> len ) == MEMCACHED_SUCCESS ) {
427- if (sid ) {
428+ else {
428429 zend_string_release (sid );
429- sid = NULL ;
430- }
431- if (-- maxfail < 0 ) {
432- return NULL ;
433430 }
434431 }
435- } while (!sid );
436-
437- return sid ;
432+ }
433+ return NULL ;
438434}
439435
440436PS_VALIDATE_SID_FUNC (memcached )
441437{
442438 memcached_sess * memc_sess = PS_GET_MOD_DATA ();
443439
444- if (memcached_exist (memc_sess -> memc_sess , key -> val , key -> len ) == MEMCACHED_SUCCESS ) {
440+ if (php_memcached_exist (memc_sess -> memc_sess , key ) == MEMCACHED_SUCCESS ) {
445441 return SUCCESS ;
446442 } else {
447443 return FAILURE ;
0 commit comments