SESSION just ends! I didn't want that!

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
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

SESSION just ends! I didn't want that!

Post by Heavy »

Code: Select all

Primary browser:               Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0
My system according to phpinfo():

Code: Select all

Version:                       php-4.2.3
System:                        Linux xxxxx.xxxxxxxxxxx 2.4.18-6mdk #1 Fri Mar 15 02:59:08 CET 2002 i686 unknown
Build Date:                    Sep 9 2002 23:20:47
Configure Command:             './configure' '--with-mysql' '--with-zlib-dir=/usr/local/lib' '--with-png-dir=/usr/local/lib' '--with-gd' '--enable-gd-native-ttf' '--with-freetype-dir=/usr/local/lib' '--with-apxs=/usr/local/apache/bin/apxs'
Server API:                    Apache
Virtual Directory Support:     disabled


Description of problem:
I have an invisible frame on my site that reloads periodically using javascript. It is included at the bottom.
Its task is to perform various things AND KEEP THE PHP-SESSION ALIVE.
After some minutes (I do not know exactly how many), the session, including the session variable $_SESSION['POLL_INTERVAL'], is
suddenly empty and the page starts to reload without delay, over and over again.

I ask myself, Why is the session unset? The page is really re-read from the server.

This "session died" experience occurs even though I am browsing the site.

Now what is wrong with my settings?
I included them below.

Someone help me out!

Code: Select all

My PHP install script:
**********
#!/bin/bash

#Unzip php:
uzut php-4.2.3.tar.gz
cd php-4.2.3/
   ./configure --with-zlib-dir=/usr/local/lib --with-png-dir=/usr/local/lib --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/local/lib --with-apxs=/usr/local/apache/bin/apxs

   make
   make install
cd ..

apachectl restart
**********





php.ini:
*****************
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30
memory_limit = 8M

їSession]
session.save_handler = files
session.save_path = /tmp
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 1
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_maxlifetime =
session.referer_check =
session.entropy_length = 0
session.entropy_file =
;session.entropy_length = 16
;session.entropy_file = /dev/urandom
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 1
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"



Apache httpd.conf:
*******************
Timeout 300
KeepAlive Off
MaxKeepAliveRequests 10
KeepAliveTimeout 15
MinSpareServers 1
MaxSpareServers 2
StartServers 1
MaxClients 150
MaxRequestsPerChild 0   # This was set to 100 before. I set it to 0 while looking for the cause of this problem

My faulty PHP script: CheckThings.php
******************************************

Code: Select all

<?php

 // This page displays no information at all. In fact, it is intended to be run in a frame with zero height.
 // It reloads periodically with a predefined interval.
 // It performs several supervising tasks.


   require_once $_SERVERї'DOCUMENT_ROOT']."/Includes/Globals.php";
   // Among other things, Globals.php sends HTTP-headers to prevent caching.


   //...Performing various things here...


   $Action = "'CheckThings.php?time=".time()."'";
  ?>
  <HTML>
   <HEAD>
   </HEAD>
   <BODY OnLoad ="<? echo $UpdateMenuStr ?>" BGCOLOR="#bbbbbb">
   <SCRIPT LANGUAGE=JAVASCRIPT>
    function Reload(){
    document.location=<?=$Action?>;
    }
    window.setTimeout("Reload()",<? echo intval($_SESSIONї'POLL_INTERVAL'])?>);
   </SCRIPT>
   </BODY></HTML>
?>
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Is there a session_start() in the code that you aren't showing us?
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

nielsene wrote:Is there a session_start() in the code that you aren't showing us?
Take a closer look:
One row of php.ini says:

Code: Select all

session.auto_start = 1
Session start works fine for the first 1 to 20 minutes of browsing.
It is after a while the error occurs.

Thank you for spending your time on me.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

I would still reccommend putting 'session_start()' at the top of each page with sessions..
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Hmm...

still... Session autostart should mean session autostart...

I'm working with ASP tonight. I'll try your suggestion tomorrow night.
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

hob_goblin wrote:I would still reccommend putting 'session_start()' at the top of each page with sessions..

Tried that.
Didn't work.

Last time I logged in to my development site, I thought I had to check how long it take before the session dies.

I logged in, rose from my chair, went to the kitchen and poured som coffe into my white little cup and got back to my holy development chair. I looked at the screen and was surprised that the session had already died!?!?! That was less that a minute!

As I write this, the site it running in another tab of netscape. Several minutes have passed now, and it still works. The only thing that differs from last time is that I have stopped apache and restarted it before logging in with a brand new session.

I did that before that less than one minute test too...

Hmmm... Session is still alive. Right now it has worked exaclty as supposed for like 7 minutes.

8 minutes...

10 minutes... Still alive..

... this is boring ...

11 minutes

Why me?

12 minutes
13 minutes.
I'm getting pretty fast typing minutes...
14 ...
15 ...
17 ...
20 ...

Äh, nu räcker det!
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

AAAH!

It died!

It took a bit over 30 minutes.
Lets try it again...

See you guys!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

have you read about session 'garbage collection'
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

hob_goblin wrote:have you read about session 'garbage collection'
Answer: Very little.

I believe that if I reload a page WITHOUT caching, it would not be seen as garbage?!?

The setting in my php.ini-file is the default:

Code: Select all

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime =
Should I modify that value?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Can't hurt ;)
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

I set
session.gc_maxlifetime = 600
It still didn't work properly, but now I'll invest some time in reading about session garbage collection.

Thank you for now. My problem is not yet solved.
MishaPappa
Forum Newbie
Posts: 7
Joined: Wed Jul 30, 2003 7:49 am
Location: Location... Location

Post by MishaPappa »

Heavy -- sorry to revive this thread of almost one year ago... but, how did you make out and resolve the timeout problem?

I'm researching a similar issue and am curious...
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

I don't remember exactly.
It was about the garbage collection process I recall. But since then, I have upgraded PHP several times, and I am not sure whether that specific problem is still there...
Post Reply