Page 1 of 1
session_start() causing the server not to respond?
Posted: Sat Jun 21, 2003 10:23 pm
by trollll
I have a problem.
I've started building a site admin page that starts at an index.php which then posts the login info to itself and then either tells the user to try again or displays the actual index page and adjusts the session to reflect that the user has now logged into the site. The page has two includes: one which searches for or creates a session (session_info.php) and another with all of the settings which won't really influence any of this posting.
The session creating page has essentially only this:
Code: Select all
<?php
session_start();
if (!isset($_GET["PHPSESSID"]) || !isset($_SESSION[ident_privileges]) || !isset($_SESSION[ident_user_id])) {
$_SESSION[ident_privileges] = $priv_guest; // $priv_guest comes from the settings page
$_SESSION[ident_user_id] = $guest_id; // $guest_id comes from the settings page
}
?>
Logging in doesn't usually cause a problem. However when the user tries to navigate to any another page which includes session_info.php and therefor calls session_start(), the server has stopped responding. It just loads until I get bored and click stop. I've let it load for up to about a half an hour with no response with four different browsers (just so I know it has nothing to do with that).
I also did some experimenting, commenting out various sections of code on different pages to see what line actually caused this to occur. The only line which, when commented out, allowed the page to load fine? session_start(), even if I didn't include session_info.php and started the session in the page navigated to.
Anyway, the thing I really don't understand: it worked fine on my machine
and the server for a while and then stopped working on the server. A little while later it stopped working on my machine stopped working as well! I checked the session files themselves to see if something odd happened during the creation process, but nothing strange happened.
Any ideas? Any clarification needed?
As a side note, the hosting company has (for PHP Version 4.2.3) the following relevant settings:
Code: Select all
register_globals = on
session.auto_start = Off
session.cache_expire = 180
session.cache_limiter = nocache
session.cookie_domain = no value
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_secure = Off
session.entropy_file = no value
session.entropy_length = 0
session.gc_maxlifetime = 1440
session.gc_probability = 1
session.name = PHPSESSID
session.referer_check = no value
session.save_handler = files
session.save_path = /tmp
session.serialize_handler = php
session.use_cookies = On
session.use_trans_sid = 1
Timeouts = Connection: 3600 - Keep-Alive: 15
HTTP_KEEP_ALIVE = 300
just in case they have something that would make this happen...
Posted: Sun Jun 22, 2003 10:02 am
by nielsene
Just a few questions:
1. What level of error reporting do you have on?
2. What is your setting for maxiumum execution time of PHP?
3. What is your webserver's timeout setting?
4. Have you checked if you ran out of disk space for storing the session?
Posted: Sun Jun 22, 2003 12:04 pm
by trollll
You'll have to forgive me if I include (or included) the wrong part of the configuration. I can configure PHP somewhat, but I still don't quite understand the whole thing yet...
nielsene wrote:1. What level of error reporting do you have on?
error_reporting = 2039
nielsene wrote:2. What is your setting for maxiumum execution time of PHP?
max_execution_time = 30
nielsene wrote:3. What is your webserver's timeout setting?
TimeoutsConnection: 3600 - Keep-Alive: 15
nielsene wrote:4. Have you checked if you ran out of disk space for storing the session?
Would that get included with the total disk space for the webserver account (if so, I have almost two gigs of breathing room), or do some hosts have a setting restricting the amount of storage space for sessions separate of disk space? If the latter holds true, how would I check that?
Thanks!
Posted: Sun Jun 22, 2003 12:47 pm
by nielsene
Hmm all those sounds ok.
Just to confirm, the page seems to load forever, without timing out, and without stopping, but showing a blank page, correct?
I remember seeing this once before, about two years ago. I'm trying to remember what caused it. It was one of those "stupid" errors that once you see it, it seems obvious....
Posted: Sun Jun 22, 2003 12:53 pm
by nielsene
Can you post any more of the script(s) so I (and other forum members) can try to test it locally?
Posted: Sun Jun 22, 2003 2:58 pm
by trollll
To confirm: the page just loads forever without giving an error, timing out or stopping. I've let it do so for up to around a half an hour with no change.
The user first comes to the index (login) page, which either displays the login form or displays the home page if the user submits correct login info. I've included the basis of the code, but can't include more of it as this project got subcontracted to me and the intranet part hasn't gone live yet, let alone the live site. Don't need cranky clients...
index.php:
Code: Select all
<?php
include("../includes/session_info.php");
$error_message;
$response;
if (isset($_POST["userName"]) && isset($_POST["userPass"])) {
$userName = $_POST["userName"];
$userPass = $_POST["userPass"];
$result_xml;
$userConnection = mysql_connect($mysql_server,$mysql_username,$mysql_password) or die("Could not connect.");
mysql_select_db($mysql_dbname) or die("Database temporarily unavailable. Please try again later.");
$query="SELECT users.userID,admins.adminLevel FROM users,admins WHERE users.userID = '$userName' AND users.pword = '$userPass' AND users.userID = admins.userID";
$result = mysql_query($query);
if ($line = mysql_fetch_row($result)) {
$_SESSION[ident_user_id] = $line[0];
$_SESSION[ident_privileges] = $line[1];
$response = getSessionID();
} else {
$error_message = "Please enter a valid user name and password.";
}
mysql_free_result($result);
mysql_close($userConnection);
}
?>
<html>...<body>...
<?php
if (isset($error_message)) {
// displays formatted error to the user
} else if (isset($response) || (isset($_SESSION[ident_user_id]) && isset($_SESSION[ident_privileges]) && $_SESSION[ident_privileges] != $priv_guest)) {
// displays home html/content to the user, along with links like the following
echo "<a href="page1.php?PHPSESSID=".session_id()."">Page 1</a>\n";
} else {
// write the login form
}
?>
</body>
</html>
When the user clicks the link to the following page, nothing loads at all. I have another version of the site I work with currently which implements the same exact code (just using cookies instead of sessions for now) and everything works perfectly. The only way that I get any response out of the following page: comment out the line "session_start();" which sits in session_info.php. So while all of that junk with XML looks like I could have an error in it somewhere, it all works fine when I don't start a session...
page1.php:
Code: Select all
<?php
include("../includes/session_info.php");
include("../includes/parseXML.php"); // holds functions getXML(server, path, query), parseResponse(xmldoc), parseErrorMessage(xmldoc)
if (isset($_SESSION[ident_privileges]) && $_SESSION[$ident_privileges] < $priv_guest) {
$parsed_error_message;
$parsed_response;
$parsed_names = Array();
$parsed_attributes = Array();
$sortThisWay = "first";
$result = getXML($server_name, "$server_modules/user/sortUsers.php", "sortBy=$sortThisWay&SESSIONID=".session_id());
if (!$result) {
$parsed_error_message = "$badXMLRequest";
} else if (ereg("^<\?xml", $result)) {
if (strpos($result, "<error_message>") > -1) {
$parsed_error_message = parseErrorMessage($result);
} else if (strpos($result, "<response>") > -1) {
$unparsed_list = explode("\n", $result);
for ($i = 2; $i < count($unparsed_list) - 1; $i++) {
$parsed_item = parseResponse($unparsed_list[0]."\n".$unparsed_list[$i]);
$div = strpos($parsed_item, ":");
if ($div > 0) {
$parsed_names[] = substr($parsed_item, 0, $div);
$parsed_attributes[] = Array();
$attributes = explode("&", substr($parsed_item, $div + 1));
for ($a=0;$a<count($attributes);$a++) {
$tempAttr = explode("=", $attributes[$a]);
$parsed_attributes[$i-2][$tempAttr[0]] = $tempAttr[1];
}
} else {
$parsed_names[] = $parsed_item;
}
}
} else {
$parsed_error_message = "No users found.";
}
} else {
$parsed_error_message = "Invalid response.\n";
}
} else {
$parsed_error_message = "Not allowed! Log in first.";
}
?>
<html>...<body>...
<?php
if (isset($parsed_error_message)) {
// displays formatted error to the user
} else if (isset($response) || (isset($_SESSION[ident_user_id]) && isset($_SESSION[ident_privileges]) && $_SESSION[ident_privileges] != $priv_guest)) {
// displays the html/content to the user
} else {
// bump the user back to index.php to login
}
?>
</body>
</html>
As a side note: I've done the XML and everything in there because later on down the road I need to access the same functions and data with Flash. Anyway, it doesn't really impact anything that causes this problem as far as I can tell. As I mentioned earlier in this posting, I have another version of the site working perfectly just using cookies instead of sessions. Possibly I didn't implement them correctly or the server got confused having globals on with me using $_SESSION?
I hope that explains things a little better... Finding it rather difficult to sum up the problem succinctly as you can probably see.

Posted: Sun Jun 22, 2003 3:24 pm
by nielsene
Hmm, I got the pages to work, without any sort of timing problems.
However I had to do the following things:
1. change a getSessionID() to session_id on index.php
2. comment out all the mysql stuff
3. comment out all the xml stuff
4. Manually set ident_user_id and ident_priv on index.php (as I don't have your login form)
Are you absolutely certain its not a mysql or xml problem? I hope someone else has some ideas.... I'll keep thinking about it, but I can't reproduce the problem.... sorry....

Posted: Sun Jun 22, 2003 3:24 pm
by cactus
May sound basic, but have you tried viewing the source of the page that seems not to have stopped loading ?
Also, are you going by a progress indicator, like in the status bar of the browser window or the animated icon (Windows logo in IE, Moz in Mozzilla), do these identify that the page is still loading ?
Just a thought.
Regards,
Posted: Sun Jun 22, 2003 3:34 pm
by trollll
The page doesn't even load enough that I can view the source. It just displays the current page (index.php) and the little icon (spinning wheel, morphing picture, spinning "e" or spinning arrows) just goes and goes and goes...