Post by sandeepmishra83 » Sat Dec 23, 2017 8:24 pm

Hi i am using opencart 3.0.2.0.. what is use of session table data. can i delete this data.
will it create any issue further or old orders/customer details will be changed.


Posts

Joined
Thu Nov 23, 2017 10:34 am

Post by straightlight » Sat Dec 23, 2017 10:39 pm

I would not suggest to manually truncate the session data. There's already an hourly set interval period to handle the sessions from the core.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fairmount » Sun Feb 18, 2018 12:18 pm

Hi,

Can I ask which part of the code handles this hourly clearance? OR is there a setting in Admin? The number of records in my OC3 session table is over 100,000 and I get only three or four visitors per day and this is over a span of just 3 months.

The site is really slow with just OC3, Journal, Openstock and vqmod installed.

Thanks.

Newbie

Posts

Joined
Fri Apr 20, 2012 11:42 am

Post by straightlight » Sun Feb 18, 2018 10:53 pm

Use TextCrawler to track lines of codes in OC. You don't need to ask the forum for these types of inquiry.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fairmount » Mon Feb 19, 2018 6:32 am

Hi Straightlight,

Thanks for the response. If I know which code to search for, I would have. I do not know which part of code within OC manages the session data database to search and hence the question. Apologies if this seems obvious, just a newbie here.

I am presuming that some part of php code within OC will go through the session table in the database and clear all the old ones. Correct me if wrong. I want to know which file within OC, Or part of the code within OC handles this os that I can check if that bit is correct in my setup.

I use use GrepWin for searching within OC, is textcrawler better than this? Will give it a go anyway.

Regards,
KG

Newbie

Posts

Joined
Fri Apr 20, 2012 11:42 am

Post by d3z1gnr » Fri May 11, 2018 7:59 am

How did you go KG? Was looking at this subject myself this morning.

fairmount wrote:
Mon Feb 19, 2018 6:32 am
Hi Straightlight,

Thanks for the response. If I know which code to search for, I would have. I do not know which part of code within OC manages the session data database to search and hence the question. Apologies if this seems obvious, just a newbie here.

I am presuming that some part of php code within OC will go through the session table in the database and clear all the old ones. Correct me if wrong. I want to know which file within OC, Or part of the code within OC handles this os that I can check if that bit is correct in my setup.

I use use GrepWin for searching within OC, is textcrawler better than this? Will give it a go anyway.

Regards,
KG

Mike Little
Director / Developer / Makes the coffee
Creative Digital Limited
http://www.creativedigital.co.nz


User avatar
Active Member

Posts

Joined
Mon Jan 18, 2010 2:59 pm
Location - Auckland, New Zealand

Post by exit15 » Thu Jun 28, 2018 11:44 pm

Running 3.0.2.0 I had 450,000 records in one website and 1 MM lines in another. So I made a copy and truncated the table just to see what happens . Everything is working just fine. The question is weather the hourly cleanup process is in fact working. Clearly there are expired session records in the table. Any Idea??

New member

Posts

Joined
Sun Mar 03, 2013 2:05 am


Post by nongetjie » Mon Dec 17, 2018 4:18 am

fairmount wrote:
Sun Feb 18, 2018 12:18 pm
Hi,

Can I ask which part of the code handles this hourly clearance? OR is there a setting in Admin? The number of records in my OC3 session table is over 100,000 and I get only three or four visitors per day and this is over a span of just 3 months.

The site is really slow with just OC3, Journal, Openstock and vqmod installed.

Thanks.
Hi, did you ever find a solution for this? I'm experiencing this right now :-(

New member

Posts

Joined
Wed Nov 07, 2012 8:28 pm

Post by nongetjie » Mon Dec 17, 2018 4:18 am

exit15 wrote:
Thu Jun 28, 2018 11:44 pm
Running 3.0.2.0 I had 450,000 records in one website and 1 MM lines in another. So I made a copy and truncated the table just to see what happens . Everything is working just fine. The question is weather the hourly cleanup process is in fact working. Clearly there are expired session records in the table. Any Idea??
Hi did you find a solution for this?

New member

Posts

Joined
Wed Nov 07, 2012 8:28 pm

Post by exit15 » Sun Dec 30, 2018 3:51 am

I did not. If fact it is a bug (check github). The system simply does not delete old session and as a result there are thousands of OC databases inflated with millions of expired records in the 'session' table. For the time being every week or so I manually delete an avg of 150,000 records with this query:

"delete from `session` where `session`.expire < DATE_SUB(NOW(), INTERVAL 1 DAY);" (Removes everything older than 1 DAY, you can write '3 HOURS' if you prefer)

Daniel suggested a few fixes when alerted to the issue, but they did not work for me because the code on github is very different than the official distribution and every-time I copied a file that he changed to resolve this problem, it created a new problem. I am not a programmer, but i wish we could just plug the above query somewhere and simply delete old sessions

New member

Posts

Joined
Sun Mar 03, 2013 2:05 am


Post by rpmb » Sun Jan 13, 2019 6:56 pm

exit15 wrote:
Sun Dec 30, 2018 3:51 am
I did not. If fact it is a bug (check github). The system simply does not delete old session and as a result there are thousands of OC databases inflated with millions of expired records in the 'session' table. For the time being every week or so I manually delete an avg of 150,000 records with this query:

"delete from `session` where `session`.expire < DATE_SUB(NOW(), INTERVAL 1 DAY);" (Removes everything older than 1 DAY, you can write '3 HOURS' if you prefer)

Daniel suggested a few fixes when alerted to the issue, but they did not work for me because the code on github is very different than the official distribution and every-time I copied a file that he changed to resolve this problem, it created a new problem. I am not a programmer, but i wish we could just plug the above query somewhere and simply delete old sessions
Thanks for this. I used the sql query you posted and used it to create a php script out of the public_html directory and then set a cron job to run it daily removing old sessions. Seemed to be the easiest automated way to prune the sessions.

opencart 3.0.2.0


User avatar
New member

Posts

Joined
Wed Jun 30, 2010 9:13 pm
Location - Cornwall

Post by thbr02 » Sat Mar 02, 2019 1:46 am

rpmb wrote:
Sun Jan 13, 2019 6:56 pm
exit15 wrote:
Sun Dec 30, 2018 3:51 am
I did not. If fact it is a bug (check github). The system simply does not delete old session and as a result there are thousands of OC databases inflated with millions of expired records in the 'session' table. For the time being every week or so I manually delete an avg of 150,000 records with this query:

"delete from `session` where `session`.expire < DATE_SUB(NOW(), INTERVAL 1 DAY);" (Removes everything older than 1 DAY, you can write '3 HOURS' if you prefer)

Daniel suggested a few fixes when alerted to the issue, but they did not work for me because the code on github is very different than the official distribution and every-time I copied a file that he changed to resolve this problem, it created a new problem. I am not a programmer, but i wish we could just plug the above query somewhere and simply delete old sessions
Thanks for this. I used the sql query you posted and used it to create a php script out of the public_html directory and then set a cron job to run it daily removing old sessions. Seemed to be the easiest automated way to prune the sessions.
Would you mind share the script? I'm in the same situation and it would be nice solving it with cron.

Active Member

Posts

Joined
Wed Jun 22, 2011 10:30 pm
Location - Sweden

Post by pm-netti » Sat Nov 02, 2019 4:45 pm

This is big bug from Opencart.

My friend was 2.5 million lines in table over two years. Very few online retailers have the skill to use cron.
This should be set on the admin page where you can set the duration of the session.
-peku-

User avatar
Active Member

Posts

Joined
Sat Apr 07, 2012 11:22 pm
Location - Kittilä, Finland

Post by letxobnav » Sat Nov 02, 2019 5:29 pm

just use files to store sessions and php will handle it in stead of OC.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by pm-netti » Sat Nov 02, 2019 7:07 pm

letxobnav wrote:
Sat Nov 02, 2019 5:29 pm
just use files to store sessions and php will handle it in stead of OC.
File system/config/default.php:

Code: Select all

$_['session_engine']       = 'db';
Why this is default setting 'db', because that recording sessions on a data insert to database is an "unfinished project" and unstable for the functioning of the trade? Can that "eternal session" jeopardize Opencart Online Stores for hacker attacks?

User avatar
Active Member

Posts

Joined
Sat Apr 07, 2012 11:22 pm
Location - Kittilä, Finland

Post by letxobnav » Sat Nov 02, 2019 7:27 pm

That is set to "db" because some guy in OC development probably read some article somewhere about storing sessions in databases and thought "why the hell not? Let's see if that works. Surely we can do better than native php session handling, besides, files are boring and databases are cool!"

That is how most functionality in OC, already working perfectly, is implemented again just in a different way.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by bitbo » Thu Oct 01, 2020 11:20 pm

I simply added this to "catalog/controller/startup/session.php"
This is triggered always when a new session is established (first call of website from anyone)


...
if (isset($_COOKIE[$this->config->get('session_name')])) {
$session_id = $_COOKIE[$this->config->get('session_name')];
} else {
$session_id = '';
}
$this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE TIMESTAMPADD(DAY, 1, expire) < NOW()");

$this->session->start($session_id);
...


This deletes all session records which are expired since one DAY (replace DAY by HOUR, if you like)
A side effect for me is that I am now able to BACKUP my database without the OUT OF MEMORY issue

Comment: There may exist better solutions - but it just works for me....

Newbie

Posts

Joined
Fri Apr 26, 2019 6:18 pm

Post by letxobnav » Thu Oct 01, 2020 11:34 pm

This is triggered always when a new session is established (first call of website from anyone)
That is triggered on every page request.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by fegdeed » Mon Oct 05, 2020 10:05 am

@letxobnav what is the best way to do it?

Image
Get a secure, fast, and reliable web hosting service from https://turnuphosting.com.


Active Member

Posts

Joined
Fri Sep 21, 2018 12:01 am

Post by letxobnav » Mon Oct 05, 2020 3:32 pm

If you want to use the database I would suggest to add a __destruct function to the session db class as the current gc function does not function.

Code: Select all

	public function __destruct() {
		if (ini_get('session.gc_divisor')) $gc_divisor = ini_get('session.gc_divisor');
		else $gc_divisor = 1;
		if (ini_get('session.gc_probability')) $gc_probability = ini_get('session.gc_probability');
		else $gc_probability = 1;
		if ((rand() % $gc_divisor) < $gc_probability) {
			$expire_dt = date('Y-m-d H:i:s', time() - ini_get('session.gc_maxlifetime'));
			$this->db->query("DELETE FROM `" . DB_PREFIX . "session` WHERE expire < '".$expire_dt."'");
		}
	}
Otherwise, use the session file class which already has a __destruct function for session garbage collection.

we store sessions in files and in addition identify bots (public and covert) and delete the session assigned to them immediately after script end as bots do not retain sessions and as such a new session is generated for bots on each page request which are subsequently useless, use space and make session clashes more likely.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan
Who is online

Users browsing this forum: No registered users and 8 guests