[RESOLVED] session_start freeze / hang issue

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

User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

[RESOLVED] session_start freeze / hang issue

Post by [UW] Jake »

Resolution: This WAS session_start(). It's a bug with MAC FIREFOX. Everything else is fine. I was going nuts for a 10-hour day, just because of my browser. I found out doing more searching that MAC FIREFOX has this issue. That's unfortunate.


Original post below:
_______________________
:banghead:

I'm working on a login system, and every time I use session_start, the page will hang and nothing happens.

The beginning of the page looks like this

Code: Select all

<?php
session_start();
 
//more code
?>
And when I try to view the page it just freezes on "waiting for mysite.com"
But when I change it to this:

Code: Select all

<?php
//session_start();
 
//more code
?>
The page loads totally fine. I've looked everywhere on the web, and people are having this problem but I've found NO solution. Putting ob_clean() before it seems to slightly help, sometimes, but not really. Is this a problem with my configuration? I've got a dedicated server which I can edit any configurations on, but I don't know anything about php configurations.

Please help! Thank you.
Last edited by [UW] Jake on Thu Jun 05, 2008 4:46 am, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: session_start freeze / hang issue

Post by Benjamin »

Have you checked your error log?
Is this a Windows or Unix server?
Are you using any custom session handlers?
Is the session directory writable?
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: session_start freeze / hang issue

Post by [UW] Jake »

astions wrote:Have you checked your error log?
Is this a Windows or Unix server?
Are you using any custom session handlers?
Is the session directory writable?

This is a Linux server (CentOS). I know how to SSH in, and edit the apache httpd.conf file. Other than that, I don't know where anything is located.

Have you checked your error log? - I don't know how
Is this a Windows or Unix server? - Unix/Linux/CentOS
Are you using any custom session handlers? - No
Is the session directory writable? - I don't know what that is or how to check



SORRY I'm such a noob at servers! I'm used to all the php code working "how it says on php.net"

This server is brand new at Softlayer.com and so it's probably all default values. We get 350,000+ visits a day and so apache's default max limit of 150 connections was the first problem I ran into, I had to configure that, which I did successfully.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: session_start freeze / hang issue

Post by Benjamin »

This is what I would do..

SSH in to the server
Type df -h to verify that there is available disk space
Type locate error_log to find the error log. On the server I'm in right now it's /usr/local/apache/logs/error_log
Type vi /usr/local/apache/logs/error_log (it may take a while to open, just wait a bit)
Scroll around and see if you find anything
To exit vi press CTRL + : or SHIFT + : then type q and press enter
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: session_start freeze / hang issue

Post by [UW] Jake »

I scrolled around, the log is HUGE cause of the ads we run or something, but the only PHP things I could find were little php warnings for fopen/fwrite/fclose on one page that isn't the one I'm working with... Couldn't find anything else about PHP.

I'm on Mac and vi was really messed up so I viewed through it with nano.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: session_start freeze / hang issue

Post by Benjamin »

Well this is a weird issue. Are you sure there is enough free disk space in the root partition?

Have you tried a blank test page to see if the problem still occurs? ie:

Code: Select all

 
session_start();
echo "Started Session";
 
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: session_start freeze / hang issue

Post by [UW] Jake »

test.php

Code: Select all

<?php
session_start();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
 
<body>
Test
</body>
</html>

This seems to work fine when I refresh it a bunch. The structure of my main page is as follows:

Code: Select all

<?php
include("modules/session.php");
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
meta tags, includes for files w/ ad codes
...
</head>
<body>
...
only DIV tags, and includes for ad codes
include for content page
...
</body></html>
 
Last edited by [UW] Jake on Thu Jun 05, 2008 12:07 am, edited 2 times in total.
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: session_start freeze / hang issue

Post by [UW] Jake »

And some from session.php

Code: Select all

 
code removed so people don't see my site's critical code
 
Last edited by [UW] Jake on Thu Jun 05, 2008 2:31 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: session_start freeze / hang issue

Post by Benjamin »

If the test page works fine then I would rule out session_start() as the culprit.

I would next look at any mysql queries, curl connections and anything else that opens a socket or can have a timeout.
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: session_start freeze / hang issue

Post by [UW] Jake »

Well it gets stuck hanging up, after clicking around a bit, then it's stuck for any given computer until I comment out session_start.

http://www.unwritten-lyts.net/index.php?page=login

use "test" and "testing" for user/pass. It'll probably say it's invalid, but keep going to the url and doing that, or refresh and 'resend'. I have no idea what's going on if it's not session_start()
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: session_start freeze / hang issue

Post by Benjamin »

I'm out of ideas. The pages are pretty heavy on ads & videos though. Maybe some of them aren't loading right away which is causing the issue.
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: session_start freeze / hang issue

Post by [UW] Jake »

I think I narrowed it down to this code

Code: Select all

//If they're not already logged in, try to validate
if(!$_SESSION['logged_in'])
{
    //Only try to validate if there is something to check on
    if(!empty($user))
    {
        //Attempt login
        include("modules/db.php");
        DB_OPEN();
        $uid = LOG_IN($user, $pass);
        if($uid != -1)
        {
            $_SESSION['logged_in'] = true;
            $_SESSION['username'] = $user;
            $_SESSION['password'] = $pass;
            $_SESSION['user_id'] = $uid;
        }
        else
        {
            LOG_OUT();
        }
        
        DB_CLOSE();
    }
}
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: session_start freeze / hang issue

Post by Benjamin »

With the traffic you are getting you may want to check that the tables are indexed correctly and give mysql more ram using my.cnf located in the /etc dir. I would look into memcache for heavy queries as well to take some of the load off the database, if indeed that is the issue.
User avatar
[UW] Jake
Forum Commoner
Posts: 25
Joined: Sun Jun 01, 2008 9:04 pm
Location: USA

Re: session_start freeze / hang issue

Post by [UW] Jake »

my.cnf:

Code: Select all

[mysqld]
set-variable = max_connections=500
safe-show-database



Is this bad? I had to set MaxClients on apache config to 10000. the thing is though, this system isn't implemented yet so nothing should have been hitting the database. I mean, the code is live, but the link to the login page is private so nobody would be causing it to go into the clause where it DB_OPEN and queries, etc.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: session_start freeze / hang issue

Post by Benjamin »

So your on a dedicated server and right now there is nothing hitting the database? It's gotta be something in the code someplace then.
Post Reply