Symfony2 FOSUSerBundle disable automatic logout after a period of inactivity - symfony

i can't seem to find the solution on how to disable auto logout after inactivity? Id like the sessions to stay alive until the browser window is closed.
Is it just the the session: config in the config files that is causing the logout or is it some FOSUSerBundle config i cannot seem to find??

Have you tried to set the sesion life time like this:
framework:
session:
cookie_lifetime: 60 #60 seconds
gc_maxlifetime: 50 #50 seconds - only needed for testing. Dont use this in a production environment
gc_probability: 1 #only needed for testing. Dont use this in a production environment
gc_divisor: 1 #only needed for testing. Dont use this in a production environment
Complete code: https://reformatcode.com

Related

How can I prevent autologout of user in Symfony 4?

When the user uses my symfony application, then after a couple of minutes the user is automatically logged out, while he is working with the application. To prevent that I changed in
config/packages/framework.yaml
framework:
session:
cookie_lifetime: 86400
gc_maxlifetime: 1800
This means the cookie lifetime is set to 24 hours. So I expect the user will only be logged out when he closes the browser. But in reality he is still automatically logged out after half in hour or so. What other options can I try?
Did you try to unset gc_maxlifetime ? It seem that PHP clear the session after this time. Moreover it's 30 minutes lifetime like your logged out problem.
framework:
session:
cookie_lifetime: 86400
You should definitively don't set gc_probability to null otherwise PHP won't ever clean your "dead" session and your server will be lack of disk space after a time.
Also it can be worth it to have a look to your php.ini configuration values because PHP will take them if they aren't specifid in Symfony configuration.
In other words Symfony override your PHP configuration if you specify somes configurations (there is a list of them )

Force update Configuration using Azure App Configuration

I want to use dynamic and central configuration strategy for my microservices (MS) (multiple instances of same type having same configuration) and I'm using Azure App Configuration (AAC). I want to minimize calls to AAC so when one MS is starting I would like to read configuration from AAC and keep that until changes made i.e I dont want for every call to Configuration["Env:service:some-param"] generate calls to AAC. The notification part I have solved via eventgrid and servicebus-events so all MSs reaches notification that changes have been made but I really cant find any good solution to force to reload Configuration from AAC on demand.
In Program.cs I hook up AAC via:
config.AddAzureAppConfiguration(options =>
options
.Connect(connection)
.ConfigureRefresh(refresh =>
{
refresh.Register(environment + ":" + service + ":<Some-param>",true)
.SetCacheExpiration(TimeSpan.FromDays(1));
_environmentRefresher = options.GetRefresher();
})
why I set SetCacheExpiration(TimeSpan.FromDays(1)) is because I dont want to make unnecessary calls to AAC and I thought that if I fetch the refresher and triggers it when event occurs configuration would be reloaded but thats seems not to be the case due to SetCacheExpiration seems to override everything so my question is ... Is given scenario not solvable in .net core or can I achieve this in some way?
Make sure to call IConfigurationRefresher.SetDirty if you want to force the cache expiration to occur using an event based refresh model. Otherwise you'll encounter the problem you mention where the cache hasn't been invalidated yet and the refresh call will be a no-op.

Symfony: logout automatically in a very short period of time

Whenever a user connect to the application after a very short period of time (like 2 or 3 minutes) he gets logged out from the application.
I thought it's the session's lifetime that being very short so I have increased it in the config.yml file like this:
framework:
session:
cookie_lifetime: 7200
But still the same problem.
The application works fine on locahost but I face this when it's running remotely!
Is there anything I should be aware of to fix this issue?
Check your session.cookie_lifetime in the php.ini file of your remote server, I'm not sure but it may override the parameters in Symfony.
After you change it, don't forget to restart php so the change is taken into account.

Autologout at random time after inactivity

I have a medical management created with Symfony 2.8 that at random time (from customer's email text) logout users after a bit of inactivity (this happen when they send a form (whatever it is)).
I have already increased the session time bringing it up to seven months.
The cache_lifetime is set to 0 ("when close your browser").
I have have tried to recreate the problem but neither me neither my collaborator have found the problem (never logged out).
Is there a way to figure out why the system logged out users or a function / controller / event to be called when there is automatic logout so that I can understand what the browser customer does ?
It is most likely your server that times out the session and not Symfony.
Anyways the best way (imo) to make sure you keep sessions in a Symfony app is to store them in the database.
# app/config/config.yml
framework:
session:
# ...
handler_id: session.handler.pdo
services:
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
public: false
arguments:
- 'mysql:dbname=mydatabase'
- { db_username: myuser, db_password: mypassword }
Full doc article: http://symfony.com/doc/current/doctrine/pdo_session_storage.html

Increase behat performance with drush driver

I am running behat inside vagrant in a drupal installation.
When I use the drush driver, in order to authenticate an admin for example, the test runs extremelly slow(2').
My behat.yml is:
default:
suites:
default:
contexts:
- FeatureMinkContext
- FeatureContext:
- "/vagrant/images/behat"
- 813
- 1855
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
selenium2: ~
javascript_session: 'selenium2'
browser_name: firefox
base_url: http://solar.com/ # Replace with your site's URL
Drupal\DrupalExtension:
blackbox: ~
region_map:
search: ".form-search"
api_driver: 'drush'
drush:
root: /vagrant/drupal
selectors:
message_selector: '.messages'
error_message_selector: '.messages.messages-error'
success_message_selector: '.messages.messages-status'
drupal:
# Replace with your real Drupal root.
drupal_root: "/vagrant/drupal"
Test structure:
#javascript #api
Feature: Tests google maps and pois
#maps
Scenario: My tests
Given I am logged in as a user with the "administrator" role
...
Didn't used drush but,
The first thing you need to do is to identify the bottleneck, maybe the server is slow, maybe you are using some method that is slow or maybe you have some waits that are not right.
Definitely something is wrong if it takes 2' for an admin authentication.
Run the scenario, debug until you narrow to the method with the issue.
Some other things you could do are:
never use blind waits, only conditional waits
if you have to fill large forms try using a javascript method for fill, it will be very fast
try different browsers, in my case chrome is slightly faster
Is it a local site setup? If yes, then behat scripts for Drupal do run a bit slow on local as compared to running it on the actual site. I have faced this in almost every project. For me, the first step which is admin authentication takes upto 5 minutes at times. Increasing the RAM size reduces this problem to some extent.

Resources