Jump to content
Peter Knight

Session problems resulting in 500 error

Recommended Posts

I have a demo site which I moved to a new VPS for client testing

We noticed that leaving a page open and then revisiting the site can result in a 25 second(ish) to load time and will then throw a 500 Error.

The hosting guys had a look and confirmed that the server is fine but the issue could be related to authentication or sessions.

We are running Page Protector and ProCache so I wondered if there were any known bugs here and any recommended actions.

My actual PW log doesn't show anything but the server log has plenty of these

 

2018-12-06 08:14:00 Error xxx.141.1x.101 500 POST /who-we-are/ HTTP/1.0     1.58 K Apache access
2018-12-06 08:14:45 Warning xxx.141.1x.131   mod_fcgid: read data timeout in 45 seconds, referer: http://demo.abc.not/who-we-are/       Apache error
2018-12-06 08:14:45 Error xxx.141.1x.131   End of script output before headers: index.php, referer: http://demo.abc.not/who-we-are/       Apache error
2018-12-06 09:03:18 Error xxx.141.1x.131   2614#0: *667 recv() failed (104: Connection reset by peer) while reading response header from upstream       nginx error

Thanks

P

Share this post


Link to post
Share on other sites
  • What mySQL version do you use?
  • Do you use DB- or file-based sessions?
  • Do you use https at all?

I've seen a few other PW threads that had similar error messages... could be plenty of stuff involved o_O

Share this post


Link to post
Share on other sites

Looks like the server is using nginx as an apache proxy. I have had a couple of PW sites on these setups and decided never again 🙂 I could never figure out what the problem was and as soon as I moved to a regular apache system everything worked as expected. Maybe someone else out there solved it and can provide a solution.

Share this post


Link to post
Share on other sites

I appreciate it could be a lot of things.

3 hours ago, dragan said:
  • What mySQL version do you use?
  • Do you use DB- or file-based sessions?
  • Do you use https at all?

I've seen a few other PW threads that had similar error messages... could be plenty of stuff involved o_O

1. I'm using 5.5.60
2. Not sure
3. Not yet but we will be when the site goes live

I think what's happening here is as follows.

1. Client logs in via page protector to their site
2. While browsing the site they leave a tab open and go into meetings etc
3. They come back 15 mins later and their session has expired
4. They try to browse the site but as their session has expired, they get a spinning / loading thing

 

Does that sound like a plausible explanation? And if so, is there a way to extend someone's Processwire session cookie for an hour or so?

P

 

Share this post


Link to post
Share on other sites

Your mySQL version is fairly recent; I don't think that has anything to do with your problems.

if you have Tracy Debugger installed, you can var_dump($config), then search for anything session-related.

You can adjust session lifetime in site/config.php (my sessionExpireSeconds is set to 86400 seconds = 24 hours = default)
https://processwire.com/api/ref/config/#pwapi-methods-session

The SessionHandlerDB module is in the core since some time: https://processwire.com/blog/posts/pw-3.0.103/#new-feature-in-session-database-core-module

 

Share this post


Link to post
Share on other sites
36 minutes ago, Peter Knight said:

They try to browse the site but as their session has expired, they get a spinning / loading thing

Do you mean browse on frontend, or try to access page editing in the backend? The backend issue is normal PW behavior when a session has expire. I guess because you are using Page Protector it's causing the same issue on the frontend.

Perhaps the login persist module might help: http://modules.processwire.com/modules/login-persist/

 

Share this post


Link to post
Share on other sites
13 minutes ago, dragan said:

Your mySQL version is fairly recent; I don't think that has anything to do with your problems.

if you have Tracy Debugger installed, you can var_dump($config), then search for anything session-related.

You can adjust session lifetime in site/config.php (my sessionExpireSeconds is set to 86400 seconds = 24 hours = default)
https://processwire.com/api/ref/config/#pwapi-methods-session

The SessionHandlerDB module is in the core since some time: https://processwire.com/blog/posts/pw-3.0.103/#new-feature-in-session-database-core-module

 

Thanks. 

I've added the sessionExpireSeconds to my config. There was nothing in place regarding this previously.

I also enabled the Module Session Handler Database and had a PHP warning within processwire as follows

Quote

 Your PHP has a configuration error with regard to sessions. It is configured to never clean up old... 28 secs 

Your PHP has a configuration error with regard to sessions. It is configured to never clean up old session files. Please correct this by adding the following to your /site/config.php file: ini_set('session.gc_probability', 1);

I'm going to add that ini_set and hope it helps.

Share this post


Link to post
Share on other sites
7 minutes ago, adrian said:

Do you mean browse on frontend, or try to access page editing in the backend? The backend issue is normal PW behavior when a session has expire. I guess because you are using Page Protector it's causing the same issue on the frontend.

Perhaps the login persist module might help: http://modules.processwire.com/modules/login-persist/

 

They are often logged into the site under PageProtector to view the front end AND  logged in via /processwire/ too.

Isn't there a way that a user can be kicked back into the pageprotector login screen if their session has expired?

 

Share this post


Link to post
Share on other sites

You could try something quick and dirty in your template file.

Before any output check if the $user is logged in on every request and redirect him to the same page if not. This should trigger your login I guess

<?php 
if(!$user->isLoggedin()){
 $session->redirect($page->url) 
}
?>

 

Share this post


Link to post
Share on other sites
1 hour ago, LuisM said:

You could try something quick and dirty in your template file.

Before any output check if the $user is logged in on every request and redirect him to the same page if not. This should trigger your login I guess


<?php 
if(!$user->isLoggedin()){
 $session->redirect($page->url) 
}
?>

 

That's not a bad idea assuming I remove it before we go live with the site.

I'll just check with @adrian that this is compatible with his page protector ?

Share this post


Link to post
Share on other sites
44 minutes ago, Peter Knight said:

That's not a bad idea assuming I remove it before we go live with the site.

I'll just check with @adrian that this is compatible with his page protector ?

That's basically what is going on with Page Protector already so I don't see how it will help.

If they reload the page and it churns for 30 seconds then I think there is something else going on. There are mod_fcgid settings that can be tweaked but as I mentioned above I tried for ages and never got anywhere. I think there is something between PW and nginx as a proxy for apache, but I couldn't figure out what it was. All the issues i had (which sound similar to yours) went away when I changed to a pure apache server (not FastCGI). Maybe others have been down this road and got things working. BTW - I didn't have PageProtector enabled and still had issues.

 

Share this post


Link to post
Share on other sites
10 minutes ago, adrian said:

That's basically what is going on with Page Protector already so I don't see how it will help.

If they reload the page and it churns for 30 seconds then I think there is something else going on. There are mod_fcgid settings that can be tweaked but as I mentioned above I tried for ages and never got anywhere. I think there is something between PW and nginx as a proxy for apache, but I couldn't figure out what it was. All the issues i had (which sound similar to yours) went away when I changed to a pure apache server (not FastCGI). Maybe others have been down this road and got things working. BTW - I didn't have PageProtector enabled and still had issues.

 

Good to know - thanks.

Do you mean choose option 2 below?

  • FastCGI application served by Apache
  • FPM application served by Apache
  • FPM application served by nginx

Share this post


Link to post
Share on other sites
18 minutes ago, Peter Knight said:

Good to know - thanks.

Do you mean choose option 2 below?

  • FastCGI application served by Apache
  • FPM application served by Apache
  • FPM application served by nginx

I'd certainly give that option a go. I am not super au fait with these managed server setups - I mostly used dedicated servers or unmanaged VPS setup, but with my limited experience, I have found that FastCGI (which uses nginx) to be a problem with PW. That said I haven't seen that much about it on these forums (https://processwire.com/talk/topic/19405-502-bad-gateway-after-24-hours-live/) so maybe it was just me 🙂 and maybe it's not the same issue you are seeing - just guessing really.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By abdulqayyum
      Dear processwire community,
      i have a problem in loginRegister module, i could not add custom field in login and register page.
      i read from plugin documentation. they are saying.
      " By default, the email and password fields are required for both forms. You may want to add more fields. To do this, you’ll need to add fields to your “user” template. You can add fields to your user template in the admin by going to “Setup > Templates > Show system templates > user”.

      but i could not find similar scenario like “Setup > Templates > Show system templates > user”
      i can see just "Setup > Templates" not seeing "Show system templates > user" in my admin panel.

      Please help me in this case that how i can add custom field in these two page.
      Regards AbdulQayyum

    • By Anton
      Hi there,
      I'm working with Processwire 3. Before summer I had issues to load to my backend. I finally managed to connect thanks to this : 
      $admin = wire('users')->get('admin');
      $admin->setOutputFormatting(false);
      $admin->set('pass', 'yo12345ZZ')
      $admin->save('pass');
      But later, the problem evolved: when I logged in to the site, the login page redirected me to the home. I didn't find any information about it on the web.
      But recently, the redirection has changed, now it is the login page that reloads when you connect. 
      I don't know where to start to fix this. It looks like sorcery.
      Thank you for all the help you can give me.
       
    • By celfred
      Hello,
      I'm facing a weird issue here. I have a page loaded with this code inside (my comments in line ends) :

      if ($session->allPlayers) { // Set in a head.inc file. I have also a $session->set('allTeams', $allTeams); in my head.inc   $allPlayers = $session->allPlayers; } else {   $allPlayers = getAllPlayers($user, false);   $session->set('allPlayers', $allPlayers); } bd($session->getAll()); // HERE, I get a number of 11 variables which is what I expect In the same page, I have a link pointing to ajaxContent.php that loads stuff via Ajax.
      I just write this in my ajaxContent.php to test :

      bd($session->getAll()); // HERE, I get only 9 variables. All my newly set $session variables ($allTeams and $allPlayers) are not conveyed to ajaxContent.php ??? Would you have any idea why is that ??? Another thing : I have a $session->headMenu set in my head.inc, and this one works fine. I can retrieve it in my ajaxContent.php page.
      I've tried cleaning all caches but it doesn't change anything 😞 
      At first, I expected it to be a 15-minute update to my site... It turns out to be a 2-hour issue and I'm still  stuck.
      Thanks for your ideas ! 
    • By angelo, italy
      Hi guys,
      I've always used WP but I want to swtich to PW. I'm not sure ....
      I'd like to know if it's possible to create a website for an online photo contest.
      The participants of the competition could create their own account, in which they upload their photos. The photos uploaded remain visible only to themselves and the judges.
      From their account they can make the "entrance fee" payment.
      The judges of the competition can create their own account... entering they see the photos of the participants and vote photos
      At the main page I imagine the title of the competition, a button to read the regulation, and a button to register.
      The website should be in Italian and English.
      Thank you!!
       
       
    • By Peter Knight
      This is probably more a server issue with Plesk etc but relates to Processwire.
      I have a very long web form which takes the average user 3-5 minutes to complete. I know it's crazy but it's a client-driven thing.
      Occasionally, my client has been emailed by users that when they eventually his Submit, they get a general 500 server error.
      I did some research and looked at some logs and it seems to be some type of time-out issue. I guess that makes sense if the form takes minutes to complete as the first two fields of the web form are attachment uploads. I'm thinking that attaching files establishes some type of session but that session expires by the time the web form is actually submitted.
      Does that sound plausible enough?
      I plan to suggest moving the attachment fields to the end of the email, disabling the webform CSFR too and seeing if things improve.
      Does my theory about file uploads and session time outs sound plausible?
       
×
×
  • Create New...