New session on reload using Apache CGI
Hi, I was just doing some testing deploying a Dancer2 app under Apache using CGI. For some reason I get a new session each time the page reloads, does anyone know why? It works fine with plackup. I am using AMPPS so it could just be something screwy with my config. Dancer App2 snippet get ‘/' => sub { session Name => ‘foo’; Dumper(session); }; get ‘/name' => sub { return session('Name'); }; Apache conf <VirtualHost *:80> ServerName localhost DocumentRoot "/testing" RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f <Directory “/testing"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all AddHandler cgi-script .cgi </Directory> RewriteRule /App2(.*)$ /App2/public/dispatch.cgi$1 [QSA,L] </VirtualHost> Cheers Mark
On Sun, 2016-02-14 at 13:02 +0000, mark jones wrote:
For some reason I get a new session each time the page reloads, does anyone know why?
What session engine are you using? It sounds like you are using Session::Simple (the default), in which case the session will only be held in memory per-process. Try another session engine, such as Session::YAML. Andy
Thanks Andy, You’re absolutely right, just after I sent the email I tried using file based sessions and it works fine. Mark
On 14 Feb 2016, at 13:40, Andrew Beverley <andy@andybev.com> wrote:
On Sun, 2016-02-14 at 13:02 +0000, mark jones wrote:
For some reason I get a new session each time the page reloads, does anyone know why?
What session engine are you using? It sounds like you are using Session::Simple (the default), in which case the session will only be held in memory per-process. Try another session engine, such as Session::YAML.
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On Feb 14, 2016, at 6:40 AM, Andrew Beverley <andy@andybev.com> wrote:
On Sun, 2016-02-14 at 13:02 +0000, mark jones wrote:
For some reason I get a new session each time the page reloads
It sounds like you are using Session::Simple (the default), in which case the session will only be held in memory per-process. Try another session engine, such as Session::YAML.
Alternately, run Apache as a reverse proxy to a constantly-running Dancer app, as described in the Dancer deployment guide: https://goo.gl/pEVzcH Then you can continue to use fast in-memory sessions.
On Sun, 2016-02-14 at 22:45 -0700, Warren Young wrote:
On Feb 14, 2016, at 6:40 AM, Andrew Beverley <andy@andybev.com> wrote:
On Sun, 2016-02-14 at 13:02 +0000, mark jones wrote:
For some reason I get a new session each time the page reloads
It sounds like you are using Session::Simple (the default), in which case the session will only be held in memory per-process. Try another session engine, such as Session::YAML.
Alternately, run Apache as a reverse proxy to a constantly-running Dancer app,
But you'd still have the same (or similar) problem, if you had more than one process serving the proxy requests? The sessions would be stored per -process, meaning that they would only be remembered if it was the same process that served the same user each request. Andy
On Feb 15, 2016, at 2:37 AM, Andrew Beverley <andy@andybev.com> wrote:
On Sun, 2016-02-14 at 22:45 -0700, Warren Young wrote:
On Feb 14, 2016, at 6:40 AM, Andrew Beverley <andy@andybev.com> wrote:
It sounds like you are using Session::Simple (the default), in which case the session will only be held in memory per-process. Try another session engine, such as Session::YAML.
Alternately, run Apache as a reverse proxy to a constantly-running Dancer app,
But you'd still have the same (or similar) problem, if you had more than one process serving the proxy requests? The sessions would be stored per -process, meaning that they would only be remembered if it was the same process that served the same user each request.
When you run Dancer under mod_proxy, there may be multiple Apache children, but there is still only one Dancer process. The only way you get into trouble here is if you’re using a multi-threaded or multi-process PSGI server (e.g. Starman) so that there are multiple global session stores in memory. My assumption in replying is that the OP was not only using Dancer[2]::Session::Simple but also running with the simple built-in web server.
participants (3)
-
Andrew Beverley -
mark jones -
Warren Young