When redeploying app on heroku PHP sessions disappear

末鹿安然 提交于 2020-02-06 06:51:06

问题


I have a Symfony app on Heroku which uses sessions (eg. to keep user logged in).



I have configured memcachier (output of heroku addons command):

Add-on                             Plan  Price
─────────────────────────────────  ────  ─────
memcachier (memcachier-flat-XXXX)  dev   free



I have also created file .user.ini in the root of my project with the following contents:

session.save_handler=memcached
memcached.sess_binary=1
session.save_path="PERSISTENT=myapp_session ${MEMCACHIER_SERVERS}"
memcached.sess_sasl_username=${MEMCACHIER_USERNAME}
memcached.sess_sasl_password=${MEMCACHIER_PASSWORD}



Also I have added to composer.json this requirement for ext-memcached:

  "require": {
        "php": ">=5.3.9",
        "ext-memcached" : "*",
        "symfony/symfony": "2.7.*",



So when I login to instance via heroku run bash and check if memcahed module is installed - it all seems fine (also phpinfo() executed served via nginx and php5-fpm returns same configuration values)

~ $ php -i | grep memcache
/app/.heroku/php/etc/php/conf.d/110-ext-memcached.ini
memcached
memcached support => enabled
libmemcached version => 1.0.18
memcached.compression_factor => 1.3 => 1.3
memcached.compression_threshold => 2000 => 2000
memcached.compression_type => fastlz => fastlz
memcached.serializer => php => php
memcached.sess_binary => 0 => 0
memcached.sess_connect_timeout => 1000 => 1000
memcached.sess_consistent_hash => 0 => 0
memcached.sess_lock_expire => 0 => 0
memcached.sess_lock_max_wait => 0 => 0
memcached.sess_lock_wait => 150000 => 150000
memcached.sess_locking => 1 => 1
memcached.sess_number_of_replicas => 0 => 0
memcached.sess_prefix => memc.sess.key. => memc.sess.key.
memcached.sess_randomize_replica_read => 0 => 0
memcached.sess_remove_failed => 0 => 0
memcached.sess_sasl_password => no value => no value
memcached.sess_sasl_username => no value => no value
memcached.store_retry_count => 2 => 2
memcached.use_sasl => 1 => 1
Registered save handlers => files user memcached 



However when inspect instance via heroku run bash and running php -i | grep session you can see that session.save_handler is still files despite configuring in .user.ini session.save_handler = memcached

session
session.auto_start => Off => Off
session.cache_expire => 180 => 180
session.cache_limiter => nocache => nocache
session.cookie_domain => no value => no value
session.cookie_httponly => Off => Off
session.cookie_lifetime => 0 => 0
session.cookie_path => / => /
session.cookie_secure => Off => Off
session.entropy_file => /dev/urandom => /dev/urandom
session.entropy_length => 0 => 0
session.gc_divisor => 1000 => 1000
session.gc_maxlifetime => 1440 => 1440
session.gc_probability => 1 => 1
session.hash_bits_per_character => 5 => 5
session.hash_function => 0 => 0
session.name => PHPSESSID => PHPSESSID
session.referer_check => no value => no value



session.save_handler => files => files
                        ^^^^^^^^^^^^^^    WTF ???


session.save_path => no value => no value
session.serialize_handler => php => php
session.upload_progress.cleanup => On => On
session.upload_progress.enabled => On => On
session.upload_progress.freq => 1% => 1%
session.upload_progress.min_freq => 1 => 1
session.upload_progress.name => PHP_SESSION_UPLOAD_PROGRESS => PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix => upload_progress_ => upload_progress_
session.use_cookies => On => On
session.use_only_cookies => On => On
session.use_strict_mode => Off => Off
session.use_trans_sid => 0 => 0

So I wonder why isn't .user.ini configuration not taking effect with real php.ini configuration?


回答1:


this is a common misconception. heroku run bash spins up a separate instance of your project. ".user.ini" conditionally gets applied when you do an actual http or https call to the project because of the path the server(nginx in your case) is taking to the file it is trying to access (web.php). Basically ".user.ini" does not apply globally nor will it ever.



来源:https://stackoverflow.com/questions/36178675/when-redeploying-app-on-heroku-php-sessions-disappear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!