Slow logout on different server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Slow logout on different server

Post by Dynamis »

So here is the situation. I am running a website on my local machine as well as a copy of the website on a server. Now on my local machine, logout is instantaneous pretty much. As for the server, it just depends on its mood I guess. Admins seem to log out instantly whereas users sometimes wait 30+ seconds. While waiting, I noticed if I hit f5, I'm still logged in, but if I click log out again after hitting f5, I log out nearly instantly. As for the server, nothing else on it lags, ever. Let me put in some of my code snippets and see if you see anything odd. Seems the code is simple and straight forward though. Not seeing the issue.

Link to logout page:

Code: Select all

 
<?php 
    if($_SESSION['logged_in']) 
        echo '<br><br>You are currently logged in [<a onClick="return confirmLogout()" href="logout.php">logout</a>]';
    else
        include("login.php");
 ?>
 
logout.php:

Code: Select all

 
<?php
    include("extras/session.php");
    $session->logout();
    header("Location: index.php");
?>
 
session function logout():

Code: Select all

 
function logout(){
    session_destroy();
}
 
Any help is appreciated.
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: Slow logout on different server

Post by Dynamis »

Well the fix was pretty stupid but it works, here is the original code:
Dynamis wrote: logout.php:

Code: Select all

 
<?php
    include("extras/session.php");
    $session->logout();
    header("Location: index.php");
?>
 
Here is the fixed code:

Code: Select all

 
<?php
    include("extras/session.php");
    $session->logout();
    header("Location: index.php");
?>
<html></html>
 
The weird part is, logout.php is an include in another file so in reality, once included the code would look something of this nature:

Code: Select all

 
<html>
<?php
    include("extras/session.php");
    $session->logout();
    header("Location: index.php");
?>
<html></html>
</html>
 
Weird, but it works....
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Slow logout on different server

Post by RobertGonzalez »

Have you tried throwing an exit() call after the header?
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: Slow logout on different server

Post by Dynamis »

I'll try tomorrow and leave some feedback.
Post Reply