How Often Does Garbage Collector Runs In Sessions?
Does anybody knows how often the session garbage collector checks for expired session to delete them? is it possible to modify this timeframe? is it possible to call this function manually?
I am storing my sessions in a mysql database and i am using a session expiration of 5 seconds (just for testing), but after the session is expired the session record in the db table still exists.
and it looks the sessions aren't expiring either because if you still have the session cookie you can keep up with the session. Code:
View Complete Forum Thread with Replies
Related Forum Messages:
Sessions And The Garbage Collector
I am trying to figure out the proper settings for session directives in php.ini and am a little confused as to exactly how php deals with session data and the garbage collection process. These are the directives I am curious about: session.gc_probability session.gc_maxlifetime My first question is how does the garbage collector work? It would appear that when the 1% chance by default of gc_probability is hit it wipes out all session data older than gc_maxlifetime, is that accurate? I am curious because on rare occasion my scripts error out due to missing session data when a user's browser is left open for the better part of the day. I am making a potentially incorrect assumption that the data has been wiped due to the garbage collector hitting its 1% chance and seeing that data is older than the 2-hour limit I currently have for the gc_maxlifetime. I would like to be able to set it up such that the gc routine cleans out session data for a user who has left their session running for longer than, say, four hours. I'm not sure exactly how these two directives work but it seems that if I set my gc_maxlifetime = 14400 and my gc_probability = 100 then every time a user starts a session it would clear out any data older than 4 hours. Is that accurate? More importantly... Is that a bad idea?
View Replies !
Problem With The Sessions' Garbage Collector
I use a custom session handler to store the sessions in a database. I use "session.gc_probability = 100" in php.ini for testing purpose. My problem: the "session_gc_method" method, the method that garbage collects the expired sessions, is called two times for each page! It is called at session_start() and at the end of the output... Am I missing something here? Shouldn't this method be called only at session_start()?
View Replies !
Session Garbage Collection
My question is this: 1.) If I set session.cookie_lifetime to 7200 and session.gc_probability to 100% will the garbage collection remove only session files that are older than 7200 seconds?' 2.) Does anyone have a good example of the header() function. I am looking for a more detailed explaination of the Cache-Control, Pragma, Expire ...
View Replies !
Garbage Collection Problem?
When I run either of the following scripts it runs to completion and prints "end" if $limit<=1e4. If $limit>=1e5 then somewhere after many loops the script stops and I do not see the final message "end". Is there garbage I should be collecting? Am I hitting a type limit? Do php scripts have any other limit that I might be hitting? I'm confused! ////////////////////////////////////////////// <?php $limit = 1e4; for ($i=0; $i<$limit; $i++) { $foo = array(); for($j=0; $j<100; $j++) { $foo[] = $j; } } echo 'end' ?> ////////////////////////////////////////////// <?php $limit = 1e4; $foo = array(); for ($i=0; $i<$limit; $i++) { for($j=0; $j<100; $j++) { $foo[$j] = $j; } } echo 'end' ?>
View Replies !
PHP Memory Garbage Collection
I have a script that uses a lot of memory and an ISP that has memory-limit set to 10 Mb. The script of course doesn't finish running. :( The program is rather simple - it parses XML into an array and then starts the loop that inserts data into the database. If I use a very large XML file then the PHP crashes inside the loop (Fatal error: Allowed memory size of 10485760 bytes exhausted) - indicating that the problem lies within loop somewhere. Can I trace memory consumption of a PHP script so I can determine where the memory is wasted? If PHP uses all the memory (and frees nothing) until the end of the script then that could be the problem - is there any way I can force it to do garbage collection? Any comment on how PHP uses memory would be appreciated - I would really hate to have to break the script into smaller pieces (or change ISP for that matter :) ).
View Replies !
Generating Garbage With SSI Files
I've enabled ob_gzhandler in my php.ini and it does seem to speed up page load. However, when I include files in the HTML pages using SSI: <!--#include virtual="/includes/header.php"--> the portion of the page that would have been the output from the header.php script is garbage.
View Replies !
Implementing Garbage Collection
so I am using the function session_set_save_handler with a mysql db to store the sessions. That all works. All I did was copy/paste and edit the example in the php manual. Now, the only thing is I have no idea how to implement the garbage collection. I tried putting just a print statement in my custom garbage collection and I don't get any output from it. I thought that it was supposed to be called up whenever a session is started? atleast as long as session.gc_probability is equal to 1? which it is. Just to let you know, in the db table I have start_time and a last accessed time columns. The way I wanted to do garbage collection was like this. if current time - last accessed time is greater than maxlifetime delete the session. I guess my main problem is just that as far as I can tell the garbage function is never getting called up.
View Replies !
Session Garbage Cleaning
I recently wrote a script that counts the sessions on the server. BUt since I'm on a shared host, it counts it for all sites on the server. Well I changed the session save path and now it saves in my public folder and the script worked how it should, only counting mine. But doing this resulted in another problem, the sessions seem to get saved, but are never deleted. I thought the PHP GC would take care of this automatically. Here is the session part of the php.ini, I thought it'd delete this after 5min: Code:
View Replies !
Session: Garbage Collection Sess_gc()
I am using the new session management feature session_set_save_handler() from PHP4. all other function is working fine, except function sess_gc($maxlifetime) . It is not working. It suppose to clean up the expired session record in my database. I have configed the file php.ini. session.gc_maxlifetime to 300 seconds. and the default session.gc_probability is Ƈ'. anyone kow what does 'session.gc_probability' do? do i have to increase the % of gc_probability? anyone know when will the server run gc process?
View Replies !
Session Garbage Collection Query
I just have a couple of questions regarding sessions. I read the php manual but I just wasn't clear on a couple of things. I am using the following to control my sessions: ... ini_set('session.save_path',"./sessions/sess/"); ini_set("session.gc_maxlifetime","300"); ini_set('session.gc_probability',1); ini_set('session.gc_divisor',1); ... I want the garbage collector to kill a users session the second a user closes their browser (or as quick as possible). Am I doing correct above ^ to achieve this? Also, are there any security issues with having the 'session.save_path' set to a directory like above or should I perhaps have it set to somewhere like "../../sessions/sess/"?
View Replies !
User Runs PHP
I have an app that uses PDFLib to read some images off the file system (Red Hat linux) and puts them into a PDF. I have permissions set on the directory to be readable by the owner and the group, 'images'. I made apache a member of the group 'images' but get a permission denied error when trying to read an image from the images directory. Is there some other user that owns the PHP app. Env. PHP 5.03 Red Hat ES4 Apache 2.02
View Replies !
PHP Only Runs From Command Line
I know very little about PHP, but I was just curious to know why exactly would some PHP code run fine from the command line but not from the browser? I'm just curious. I was working with someone else's PHP code that supposedly created MySQL tables in a database and for some reason it just wouldn't create the tables at all (no specific error message). Someone suggested I run from the command line and when I did, it worked...
View Replies !
Bad Query Runs With No Error!
there must be some weird setting on the mysql database i am using for this latest project. the following query runs without throwing an error: SELECT start_time, last_access_time, user_ip session_data FROM demo_sessions WHERE id='b31fd40c7e9135f2b52e4f17c23fc3c54da137b8' notice there is no comma between user_ip and session_data what's the story here? seems like a real security risk to me because my server won't log bad requests.
View Replies !
Why Script Runs Differently With CRON?
I am running a PHP Script that downloads my RSS News (and the accompanying Thumbnail images)from the Web. When I execute it from CMD line, no problem. The News and Images are downloaded, great! When I begin to update via CRON, no images are downloaded/written to disk.--I don't have this problem when it's RUN from a shared hosting account, it's only on my home Linux Box.
View Replies !
Bug 23891 MySQL Runs Out Of Connections
http://bugs.php.net/bug.php?id=23891 According to this report, what the person was asking isn't a bug, it's a feature (rimshot). I'm running into this problem almost exactly, and really don't understand what the answer is. The support person snidely suggests reading the manual, which is always great advice, but in this case really doesn't help out. Could someone explain what "If you use mysql_select_db() or slightly different connection string you can have more open connections then you have process." means? If I don't use mysql_select_db, then what do I use?
View Replies !
EXEC() Runs Process In Background
Exec, shell_exec, system, popen functions all run the process in the background. how can i get it to run the process normally. my code looks like this: <? exec("batch_file.bat"); ?> am i doing anything wrong?
View Replies !
Close Window After Script Runs
When a user clicks on a link in their email, I have a browser window that opens in the background and runs a script confirming their desire to be added to our email directory. I basically want this window to open, run and then close without the user having to deal with it. Is there a way in PHP to close the window after the script finishes running in it? Or should I revert to JavaScript? I want the script to be mobile so I've sort of ruled out processing it server side. TIA.
View Replies !
Email Form Which Runs From An Iframe
I have set up an email form which runs from an iframe. The only problem is that when the script redirects the user to the success or error pages, these pages open within the iframe. Is there a way to specify the target window as 'parent'? Someone said that this could not be done via the php script and would have to be done with javascript in the html form itself.
View Replies !
Optimizing Query That Runs Slowly On Linux
I was wondering if anyone has any insight into why the query I have posted below runs exceedingly slow on my Linux server. I am using Php with a MySQL database. On both my development computers the query runs briskly. They are however both Windows boxes, one running Windows XP and the other running Windows 2000 Professional. Here is the culprit.....
View Replies !
Header Function Runs Before Update To Database Is Made
I have been having some problems with a part of my login script. This is the two lines of script I am having problems with: mysql_query("UPDATE " . $userName. " SET login = '$loginIN' WHERE pass = '$password' AND course = '$courseID'"); header( 'url=http://www.somewebsite.com/logged_IN.htm' ); The problem is that when this php script is executed the second line executes before the first and an update to the database is not made. I also tried the script without the second line and the first works then.
View Replies !
Query Runs In Mysql But Returns Error 1064
The same query runs in mysql and in Zend interface but not runs when using inside php script. I am receiving the error: "1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'str_qry_Insert' at line 1" INSERT INTO fnd_script_type (type_name) VALUES ('test1') I already have tried it with as: INSERT INTO `fnd_script_type` (`type_name`) VALUES (`test1`) INSERT INTO fnd_script_type (`type_name`) VALUES (`test1`) INSERT INTO fnd_script_type (type_name) VALUES (`test1`) what am i doing wrong ?
View Replies !
Query Runs Multiple Times Under Heavy Server Load.
I have been having an issue with some MYSQL queries running multiple times when the server is under a heavy load. Example, if I do an 'update Table1 set item1 = 0 where 1 = 1' This runs fine under normal conditions, but will repeat itself multiple times when the server is under load. Is this just an optimization or server resource issue. If so, I would assume the query would just timeout and not run at all instead of running a few times.
View Replies !
Working With Dates - Runs And Queries The Database To Produce A List Of Information
I have a script that runs and queries the database to produce a list of information, based on a date range. This is to fllow up on a script that is automatically run each Sunday night. What I want to try and acheive is, for example, if someone manually runs this report on a Tuesday the script will assume that it is run on the Sunday night, to make sure the results are exactly the same as the emails that have gone out. PHP Code:
View Replies !
Form Submission Fills Form Values With Garbage
I'm attempting to do some form processing on a server that has register_globals off, however, I've run into a confusing situation and need some help. Basically, the form is a multi-part/form-data form as I have it upload a file in addition to submit a number of other fields, but the error I have occurs even when no upload is done. When I submit the form, all my input field variables get filled with garbage. Here's the html before submission for one of the fields: Code:
View Replies !
"Please Wait" Page While Php Runs Mysql Queries
Does anyone have any idea what I should google to create a "splash page" that tells the user to wait while a few mysql quieries are run through the php page? It takes anywhere from 5 to 20 seconds, and I don't need a progress meter, just a splash page so they do not go anywhere and the user doesn't think there is a problem with their browser or network connection.
View Replies !
Creating User Sessions W/out Using Sessions
I'm working on a user management system where I can use the benefits of PHP sessions w/out messing with them. Basically, my idea is to have an entry created into a "sessions table" when the user logs in. The table contains such info as the user's id number and the date/time they logged in. When the user logs out, the entry is deleted. In each page/script, it checks to see if the user is logged in by checking the sessions table for an entry w/their IP address and the date, to make sure it is fairly current (unless anyone can think of a better way to check). Now my delema....obviously, I don't want people that don't properly log out to have a session that could last weeks (depending on when they visit again). I am thinking a script that cleans up entries that are old would do the trick, but obviously I want this script to run say, at least once an hour. Obviously, I am not going to be able to sit at my computer and run this script every hour of every day. I was thinking of using the script and doing a cron job, but I think my host only allows one cron job per day...and only at night. Any thoughts??
View Replies !
How Do Different Sessions Work? Multiple Sessions
I use a messageboard which uses sessions. I have a login script which uses sessions. I have a charting app which uses sessions. How does PHP handle this? Does it create three different sessions or is everything handled by the one session file? In other words, is it working like magic and I don't need to worry about it. What I'm confused with is that at the start of the login script there is a start_session() and other session related stuff. On logout, the session is destroyed. Now does this affect the start_session() of the other scripts?
View Replies !
Php Runs Slower And Slower
I have phpmysql runs to fetch information from a database.One proble I have is that as the number of rows it fetched, it ran slower and slower. Sometimes it even says the query is wrong, although it is not.
View Replies !
Sessions Help
I am getting strage problems with sessions - actually rarely used them before. I am basically just testing passing a session variable from one page to another. Everything works great when uploaded to my hosting server but not when used locally! Locally I am using Apache 1.3.20 and Php 4.0.6 on win2k with browser IE6 I am using the simplest session setup - PAGE 1 session_start(); $_SESSION['name'] = "Kevin"; echo $_SESSION['name']; Then a link to the second page - PAGE 2 session_start(); echo $_SESSION['name']; As I said everything works great on the hosting server but not locally. I have looked at the output from phpinfo() on PAGE 2 and it shows that the session is being created and even has a value - PHPSESSID=4c0ba2b373b1faf9dfd0c1c98705dfa0 This value showing in HTTP_COOKIE , Cookie and HTTP_SERVER_VARS["HTTP_COOKIE"] The sessions are stored as cookies and if I look in the php/temp directory yup they are there! So it looks like the sessions are being started, store the data in the cookie ok but are not being read on PAGE 2. As I mentioned on the hosting server it works great. Can someone please give us a clue why it isn't working locally? thanks Kevin PS I also tried including a session_register('name') as well as the older $HTTP_SESSION_VARS["name"] = "Kevin";
View Replies !
Sessions That Do Not End?
Does anyone know of anything that would make a session constant even after a user ends the session by closing the browser? I am using sessions to assign users unique id's and when the user comes back to the site, they are being assigned the same session id, therefore making the entire concept useless.
View Replies !
Sessions And IE5 Or 6?
I had sessions working just fine and then all of a sudden they stopped working. I'm wondering if IE5 or 6 handles sessions differently. Anyone had a similiar experience? If not I guess I'm back to the drawing board. If anyone can help me get started with the proper way to start a session I would appreciate it. What I have is a session id and 2 variables. It seems that I can log in and the session is started but when I click on a link on the username page it forgets about the session that was created and I'm back on the login page again with no tracce of the session. <?php session_start(); session_register('username'); session_register('isloggedin'); if (!isloggedin) { loginmenu(); } else { usermenu($username); } ?>
View Replies !
Now You See It, Now You Don't Sessions
This one has me completely stumped. I have a simple site where I'm using sessions to keep track of some information across multiple pages. The trouble is, when I go to a page that displays the information, sometimes I can see the information and sometimes I can't. If I refresh the same page, the information may appear or not in a completely random manner. And nothing is writing to the session variable anywhere in the page. I have displayed the information and it is definitely not there when the information does not appear. I have checked the session id and it remains the same regardless of whether the info appears or not. The code runs fine on my local server (PHP 4.3.2) but not the ISP's server (PHP 4.1.2). My question is - What on earth is going on here? - And if the info is wiped out of the session array on a particular page request, how does it reappear at some random page refresh? Any ideas or thoughts from anyone would be greatly appreciated.
View Replies !
Sessions And CLI
Im currently working on a collection of scripts that will work in command line only. Im using the latest version of PHP. Ive got problems figuring out how to start a session with a specific session_id. Maybe im doing something wrong here, but ive got no idea what. It seams that if I call session_start($id), where $id is a sessionid that i know for sure was already registered earlier, that specific session does not get initialized. See this simple test script PHP Code:
View Replies !
Sessions+ssl
we are using apache OpenSa, with php on a win2k machine, we are having problems with sessions, the sessions are working under the normal apache server,, however when we use the OpenSa ssl component it wont work properly,,,we get the following errors,,,any ideas? Warning: open(/tmpsess_50ca39a0d25cd9d3b98290de9a5379d5, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0 i have created the session file in the php folder and put its path into the php.ini file,
View Replies !
Sessions / PHP 4.3.1
I have a website, to which members must "log on" to gain access. The sequence of pages is as follows: 1. index.php Contains form for username/password 2. login.php starts session <? session_start(); session_register("user_id"); session_register("logged_in"); ?> validates authentication A - if "ok" i. sets $user_id and $logged_id ii. goes to membersArea_frameset.php B - if fails - goes to an error page This setup normally works fine, for 99% of visitors. However, every day i get a few emails from people who receive an error message saying that the session has expired, rather than a successful login. Each page (including the above frameset page) has an include of 'session_check.php'. The contents of the file is: <? if ($logged_in != session_id()) { echo "<script>self.location='error.php?error=2'</script>"; exit(); } ?> For nearly all visitors, the above setup works fine. Any ideas why some people are told straight after successfully logging in that their session has expired? This is really worrying. I can't figure it out. Have I not set up the sessions correctly? PHP - Version: 4.3.1
View Replies !
PHP Sessions And IE6
I have a website (e.g. www.mainsite.com) with a MySQL database and I use PHP for members to login, adddel records. Their UserID is recorded in a session variable. I have a second website where the files are located at www.mainsite.com/subdirectory/ and I use framed web forwarding from my ISP which makes it look like www.secondsite.com is actually the contents of this sub directory. I do this because www.secondsite.com is a customised website for that company but accesses the same database. With IE5 when you login to the database via www.secondsite.com it works fine but since i've upgraded to IE6 it gives me a login error. And I remember there is some new Cookie security thing from Microsoft.
View Replies !
Sessions!
i need to create something that will keep the username in 'store' so that it is available to any page on my site that has the members area 2) i need to have code that checks if the 'store' is there, and if the username is in the MySQL db if its there, i need it to display the page content if not...i need it to display a "You are not a member or bad password"
View Replies !
Sessions - SID
I use sessions, if the user doesn't have cookies enabled the query string ?SID=xxx will be at the end of every URL. But...when the user does have cookies enabled this still happens for the first page, an example of a session (urls): http://x.com/ http://x.com/alinkfromxcom/?SID=xxx http://x.com/alinkfrom_alinkfromxcom/ Just a session id on the first link clicked on then it goes away... Does anyone know why?
View Replies !
Is Sessions With 4.1 Different Than >4.x
I've run into some trouble sessions and it seems to be when I upgraded php to 4.1 Is there some documentation that describes the different coding you should use for versions less than or greater than 4.1. Currently I 'm using this main log in page session_start(); $_SESSION["userid"] = "$userid"; $_SESSION["departments"] = "$departments"; and then on every other page I have this at the top session_start(); pretty straight forward if you ask me but for some reason it doesn't want to work and i was just wondering if there was new things that I wasn't aware of.
View Replies !
Ie6 And Sessions
i have a problem with ie6 and sessions in popups. When i open one popup, the session opens as usual, but if i open second popup from the first popup, the session is gone. Has anyone expirienced something similar? anyone knows how to solve the problem?
View Replies !
Sessions In Php 4.1
Our server upgraded to PHP 4.1 on 12/21/01 and now my sessions are not being globally set. 4.1 deprecates session_register(), but still supports it if it is enabled in php.ini which it is on my server. The /tmp is correct and and this smae exact script works on my desktop server using 4.05. When I login to my CMS from an index.php, it opens to the default page, but if you refresh or go to any link, it loses the registered login variables. Anyone else having similar probs? PHP Code:
View Replies !
|