Advertisement:

Author Topic: Memcache and sessions  (Read 803 times)

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 72,371
    • StoryBB/StoryBB on GitHub
Re: Memcache and sessions
« Reply #20 on: May 21, 2020, 02:53:44 PM »
Quote
I was referring to SMF > Administration Center > Server Settings > Caching displaying "SMF has detected that your server has Memcached installed.", I take this to mean that Memcache(d) is doing something there, even if sessions are not set up. Please correct me if I am wrong.

It has detected the memcache (no d) connector -> https://www.php.net/memcache (supported for caching in 2.0 and 2.1)
And the memcached (with d) connector -> https://www.php.net/memcached (supported for caching in 2.1 only)

SMF having detected or not detected this has zero bearing on sessions.


Re Redis... did I use an existing mod? No, I rolled my own. No, you can't use it with SMF because it wasn't written for SMF, it was written for a fork meaning that your ability to use it is limited. However if for some reason you did want to look, here's the class I wrote.

Redis for sessions works the same way as Memcache, you configure it in the php.ini via TCP.

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,859
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Re: Memcache and sessions
« Reply #21 on: May 21, 2020, 03:23:52 PM »
Thanks again, Arantor.

I've put this on my htaccess. Not sure though if that has taken effect. Checking the cookies through the browser lock icon does not include the one I set for memcache (memcachecookiesmf2).

https://www.translatum.gr/forum/index.php

Code: [Select]
<IfModule php7_module>
php_value session.gc_maxlifetime = "96000"
php_value session.save_path = "tcp://127.0.0.1:11211"
php_value session.save_handler = "memcache"
php_value session.cookie_lifetime = "96000"
php_value session.cookie_secure = "1"
php_value session.entropy_file = "/dev/urandom"
php_value session.entropy_length = "32"
php_value session.hash_function = "0"
php_value session.name = "memcachecookiesmf2"
php_flag session.use_cookies = On
php_flag session.use_only_cookies = On
php_flag session.use_strict_mode = On
php_flag session.use_trans_sid = Off
</IfModule>

This is what I see in my php.info

memcache
memcache support   enabled
Version   4.0.2
Revision   $Revision$

memcache.allow_failover   1   1
memcache.chunk_size   32768   32768
memcache.compress_threshold   20000   20000
memcache.default_port   11211   11211
memcache.hash_function   crc32   crc32
memcache.hash_strategy   consistent   consistent
memcache.lock_timeout   15   15
memcache.max_failover_attempts   20   20
memcache.prefix_host_key   0   0
memcache.prefix_host_key_remove_subdomain   0   0
memcache.prefix_host_key_remove_www   1   1
memcache.prefix_static_key   no value   no value
memcache.protocol   ascii   ascii
memcache.redundancy   1   1
memcache.session_prefix_host_key   0   0
memcache.session_prefix_host_key_remove_subdomain   0   0
memcache.session_prefix_host_key_remove_www   1   1
memcache.session_prefix_static_key   no value   no value
memcache.session_redundancy   2   2
memcache.session_save_path   no value   no value

Offline drewactual

  • Sr. Member
  • ****
  • Posts: 834
    • College Football Fan Site CFB51
Re: Memcache and sessions
« Reply #22 on: May 21, 2020, 03:35:19 PM »
If you're using OPCache, you'll need to reset it.  Otherwise, dump your browser cache.

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,859
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Re: Memcache and sessions
« Reply #23 on: May 21, 2020, 03:49:42 PM »
I used this to reset OPCache. Restarted Apache, php-fpm, emptied browser cache. No change.

Code: [Select]
<?php
opcache_reset
();
?>

Offline drewactual

  • Sr. Member
  • ****
  • Posts: 834
    • College Football Fan Site CFB51
Re: Memcache and sessions
« Reply #24 on: May 21, 2020, 04:40:51 PM »
Weird... check your directory where sessions were/are stored when using files, and see if it has very recent entries?

Offline Herman's Mixen

  • SMF Hero
  • ******
  • Posts: 7,276
    • HermanMixen on Facebook
    • @Hermans_Mixen on Twitter
    • Herman's Mixen
Re: Memcache and sessions
« Reply #25 on: May 21, 2020, 04:48:25 PM »
Just a throw back here look for your own distro wich you use here just an example

https://devdocs.magento.com/guides/v2.3/config-guide/memcache/memcache_ubuntu.html
Met vriendelijke groet, The Burglar!

 House Mixes | Mixcloud | Any Intelligent fool can make things bigger, more complex, and more violent.
It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Albert Einstein

Former Godfather of our dutch community ;)

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,859
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Re: Memcache and sessions
« Reply #26 on: May 22, 2020, 04:17:45 AM »
Weird... check your directory where sessions were/are stored when using files, and see if it has very recent entries?

Not sure what that is. In php.ini I see:
session.save_path   /var/cpanel/php/sessions/ea-php71   /var/cpanel/php/sessions/ea-php72

And both are empty.

I removed from htaccess and added in Pre VirtualHost Include in Apache using the path to the forum.

Just a throw back here look for your own distro wich you use here just an example

I tried the script listed there, it returns HTTP ERROR 500.
Checking
Code: [Select]
stats items via cmd gives:

Code: [Select]
STAT items:25:direct_reclaims 2873
STAT items:25:hits_to_hot 1109
STAT items:25:hits_to_warm 1284
STAT items:25:hits_to_cold 267
STAT items:25:hits_to_temp 0
STAT items:26:number 76
STAT items:26:number_hot 8
STAT items:26:number_warm 1
STAT items:26:number_cold 67
STAT items:26:age_hot 1383
STAT items:26:age_warm 3166
STAT items:26:age 7861
STAT items:26:evicted 1769
STAT items:26:evicted_nonzero 1769
STAT items:26:evicted_time 7826
STAT items:26:outofmemory 0
STAT items:26:tailrepairs 0
STAT items:26:reclaimed 1352
STAT items:26:expired_unfetched 1464
STAT items:26:evicted_unfetched 1225
STAT items:26:evicted_active 0
STAT items:26:crawler_reclaimed 391
STAT items:26:crawler_items_checked 9676
STAT items:26:lrutail_reflocked 0
STAT items:26:moves_to_cold 2715
STAT items:26:moves_to_warm 85
STAT items:26:moves_within_lru 22
STAT items:26:direct_reclaims 1769
STAT items:26:hits_to_hot 742
STAT items:26:hits_to_warm 49
STAT items:26:hits_to_cold 229
STAT items:26:hits_to_temp 0
STAT items:27:number 60
STAT items:27:number_hot 11
STAT items:27:number_warm 2
STAT items:27:number_cold 47
STAT items:27:age_hot 1282
STAT items:27:age_warm 462
STAT items:27:age 7451
STAT items:27:evicted 1231
STAT items:27:evicted_nonzero 1231
STAT items:27:evicted_time 8017
STAT items:27:outofmemory 0
STAT items:27:tailrepairs 0
STAT items:27:reclaimed 1119
STAT items:27:expired_unfetched 1085
STAT items:27:evicted_unfetched 826
STAT items:27:evicted_active 0
STAT items:27:crawler_reclaimed 269
STAT items:27:crawler_items_checked 7218
STAT items:27:lrutail_reflocked 0
STAT items:27:moves_to_cold 1857
STAT items:27:moves_to_warm 102
STAT items:27:moves_within_lru 1104
STAT items:27:direct_reclaims 1231
STAT items:27:hits_to_hot 661
STAT items:27:hits_to_warm 1301
STAT items:27:hits_to_cold 208
STAT items:27:hits_to_temp 0
STAT items:28:number 36
STAT items:28:number_hot 7
STAT items:28:number_warm 0
STAT items:28:number_cold 29
STAT items:28:age_hot 1445
STAT items:28:age_warm 0
STAT items:28:age 12075
STAT items:28:evicted 485
STAT items:28:evicted_nonzero 485
STAT items:28:evicted_time 21750
STAT items:28:outofmemory 0
STAT items:28:tailrepairs 0
STAT items:28:reclaimed 2171
STAT items:28:expired_unfetched 3180
STAT items:28:evicted_unfetched 319
STAT items:28:evicted_active 0
STAT items:28:crawler_reclaimed 1527
STAT items:28:crawler_items_checked 14271
STAT items:28:lrutail_reflocked 0
STAT items:28:moves_to_cold 2221
STAT items:28:moves_to_warm 215
STAT items:28:moves_within_lru 209
STAT items:28:direct_reclaims 485
STAT items:28:hits_to_hot 1779
STAT items:28:hits_to_warm 343
STAT items:28:hits_to_cold 241
STAT items:28:hits_to_temp 0
STAT items:29:number 36
STAT items:29:number_hot 6
STAT items:29:number_warm 2
STAT items:29:number_cold 28
STAT items:29:age_hot 811
STAT items:29:age_warm 26
STAT items:29:age 12149
STAT items:29:evicted 370
STAT items:29:evicted_nonzero 370
STAT items:29:evicted_time 23414
STAT items:29:outofmemory 0
STAT items:29:tailrepairs 0
STAT items:29:reclaimed 1583
STAT items:29:expired_unfetched 1800
STAT items:29:evicted_unfetched 223
STAT items:29:evicted_active 0
STAT items:29:crawler_reclaimed 558
STAT items:29:crawler_items_checked 4795
STAT items:29:lrutail_reflocked 6
STAT items:29:moves_to_cold 1415
STAT items:29:moves_to_warm 243
STAT items:29:moves_within_lru 4181
STAT items:29:direct_reclaims 370
STAT items:29:hits_to_hot 488
STAT items:29:hits_to_warm 11779
STAT items:29:hits_to_cold 366
STAT items:29:hits_to_temp 0
STAT items:30:number 13
STAT items:30:number_hot 2
STAT items:30:number_warm 1
STAT items:30:number_cold 10
STAT items:30:age_hot 1578
STAT items:30:age_warm 2865
STAT items:30:age 10254
STAT items:30:evicted 160
STAT items:30:evicted_nonzero 160
STAT items:30:evicted_time 26761
STAT items:30:outofmemory 0
STAT items:30:tailrepairs 0
STAT items:30:reclaimed 374
STAT items:30:expired_unfetched 222
STAT items:30:evicted_unfetched 91
STAT items:30:evicted_active 0
STAT items:30:crawler_reclaimed 142
STAT items:30:crawler_items_checked 1560
STAT items:30:lrutail_reflocked 0
STAT items:30:moves_to_cold 528
STAT items:30:moves_to_warm 53
STAT items:30:moves_within_lru 30
STAT items:30:direct_reclaims 160
STAT items:30:hits_to_hot 255
STAT items:30:hits_to_warm 57
STAT items:30:hits_to_cold 189
STAT items:30:hits_to_temp 0
STAT items:31:number 16
STAT items:31:number_hot 0
STAT items:31:number_warm 0
STAT items:31:number_cold 16
STAT items:31:age_hot 0
STAT items:31:age_warm 0
STAT items:31:age 11962
STAT items:31:evicted 181
STAT items:31:evicted_nonzero 181
STAT items:31:evicted_time 3252
STAT items:31:outofmemory 0
STAT items:31:tailrepairs 0
STAT items:31:reclaimed 1900
STAT items:31:expired_unfetched 2352
STAT items:31:evicted_unfetched 144
STAT items:31:evicted_active 0
STAT items:31:crawler_reclaimed 750
STAT items:31:crawler_items_checked 2137
STAT items:31:lrutail_reflocked 0
STAT items:31:moves_to_cold 2049
STAT items:31:moves_to_warm 53
STAT items:31:moves_within_lru 17
STAT items:31:direct_reclaims 181
STAT items:31:hits_to_hot 273
STAT items:31:hits_to_warm 26
STAT items:31:hits_to_cold 144
STAT items:31:hits_to_temp 0
STAT items:32:number 12
STAT items:32:number_hot 0
STAT items:32:number_warm 0
STAT items:32:number_cold 12
STAT items:32:age_hot 0
STAT items:32:age_warm 0
STAT items:32:age 9329
STAT items:32:evicted 60
STAT items:32:evicted_nonzero 60
STAT items:32:evicted_time 4198
STAT items:32:outofmemory 0
STAT items:32:tailrepairs 0
STAT items:32:reclaimed 1683
STAT items:32:expired_unfetched 2194
STAT items:32:evicted_unfetched 48
STAT items:32:evicted_active 0
STAT items:32:crawler_reclaimed 895
STAT items:32:crawler_items_checked 2849
STAT items:32:lrutail_reflocked 0
STAT items:32:moves_to_cold 2312
STAT items:32:moves_to_warm 98
STAT items:32:moves_within_lru 25
STAT items:32:direct_reclaims 60
STAT items:32:hits_to_hot 258
STAT items:32:hits_to_warm 28
STAT items:32:hits_to_cold 272
STAT items:32:hits_to_temp 0
STAT items:33:number 2
STAT items:33:number_hot 0
STAT items:33:number_warm 0
STAT items:33:number_cold 2
STAT items:33:age_hot 0
STAT items:33:age_warm 0
STAT items:33:age 9329
STAT items:33:evicted 4
STAT items:33:evicted_nonzero 4
STAT items:33:evicted_time 196
STAT items:33:outofmemory 0
STAT items:33:tailrepairs 0
STAT items:33:reclaimed 214
STAT items:33:expired_unfetched 196
STAT items:33:evicted_unfetched 4
STAT items:33:evicted_active 0
STAT items:33:crawler_reclaimed 130
STAT items:33:crawler_items_checked 322
STAT items:33:lrutail_reflocked 0
STAT items:33:moves_to_cold 427
STAT items:33:moves_to_warm 76
STAT items:33:moves_within_lru 8
STAT items:33:direct_reclaims 4
STAT items:33:hits_to_hot 26
STAT items:33:hits_to_warm 8
STAT items:33:hits_to_cold 235
STAT items:33:hits_to_temp 0
« Last Edit: May 22, 2020, 04:49:36 AM by spiros »

Offline drewactual

  • Sr. Member
  • ****
  • Posts: 834
    • College Football Fan Site CFB51
Re: Memcache and sessions
« Reply #27 on: May 22, 2020, 10:16:00 AM »
In your phpinfo there is no save path configured either for the server or site...

Check the line sessions.save_path... it may use different context that how we've set it up... again, I used memcacheD for sessions freeing memcache for caching... I didn't see memcached loaded on your phpinfo... the version that can be ported to php7, I thought, was for cache only and didn't have sessions capability...

I can't tell you I've ever got memcache to work handling sessions but memcached has worked for several years now.  After looking last night it HAS been ported to 7.2php and is available in the RPM library, and can be 'yummed" right in...

If you bring in memcacheD, you can have it running sessions in just a few minutes with the info provided already... the only thing not here is the four lines of configuration.... that is easy enough, though.


Offline drewactual

  • Sr. Member
  • ****
  • Posts: 834
    • College Football Fan Site CFB51
Re: Memcache and sessions
« Reply #28 on: May 28, 2020, 01:09:15 PM »
I ran across a snippet last night and intended to provide it here.. but, alas, SOMETHING SHINY!!! and the link is forgotten...

At any rate, it read that Memcache CAN be ported to php7 but it isn't suitable for anything but cache.  Not without a lot of effort and coding can it be used for sessions.  MEMCACHED, however, can out of the box.  The 'box' is available in most RPM libraries now.  And of it isn't, it can be yummed in from several certified sites.