Creating a dummy session

Discussion forum for MOD Writers regarding MOD Development.
Locked
Tomba
Registered User
Posts: 134
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Creating a dummy session

Post by Tomba » Mon Oct 14, 2013 6:54 pm

I was wondering what would be the best way to create a session from which I do not want to know anything.

Basically, for feed pages and simple stuff, I'm not really interested in tracking the users, so I would prefer not to make any database query. However, I do need the database functionality and the language properties.

Any ideas how this could be realised best? I see $user->session_begin() actually checks GET and SESSION parameters, so I don't think that really is an option.

Is it feasible to create an empty user object and use that from there on?
What properties would I definitely have to set?

User avatar
EXreaction
Former Team Member
Posts: 5666
Joined: Sun Aug 21, 2005 9:31 pm
Location: Wisconsin, U.S.
Name: Nathan

Re: Creating a dummy session

Post by EXreaction » Tue Oct 15, 2013 2:17 am

It's certainly possible, however there is quite a bit of work required, especially if you want to use things like templates or other features.

Do you only want to use the database abstraction layer and the language/translation system from phpBB or are there other features you want to use?

Tomba
Registered User
Posts: 134
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: Creating a dummy session

Post by Tomba » Tue Oct 15, 2013 8:13 pm

Well I think DB and language would be enough, as I'm only generating XML.

My main problem is that my feeds are sometimes getting hammered by bots, usually with useragents never seen on any other page. That alone causes a lot of UPDATE and INSERT into the sessions table, which then gets sluggish and influences my users.

So, the main thing for me would be to create an anonymous usersession without adding it in the database and work from there.

User avatar
EXreaction
Former Team Member
Posts: 5666
Joined: Sun Aug 21, 2005 9:31 pm
Location: Wisconsin, U.S.
Name: Nathan

Re: Creating a dummy session

Post by EXreaction » Tue Oct 15, 2013 11:40 pm

Then it should be too terribly difficult.

You'd want to go through the code for the dbal to see what it all needs. You'll probably need to include functions.php and you might need to initiate the cache as well (I do not recall exactly for 3.0).

Just include the correct files and setup the dbal (see what's done in common.php).

As for the language, you shouldn't need to use the whole user/session object. Either manually include the language files you need (i.e. include(lang/en/common.php)) or you can setup the user class then just setup the variables needed to use the add/set/lang functions (review the code and see what variables it uses).

If you don't want quite so much work you could include common.php, which would setup most of the stuff you need, and don't call user->setup() (which is where sessions are setup). It includes a lot more functions/classes you may not need, but it'll be a lot easier for you. You will still (probably) need to set the variables properly in the user object to properly load the language files.

Tomba
Registered User
Posts: 134
Joined: Tue Jun 18, 2002 7:52 am
Location: Belgium
Name: Steven De Groote
Contact:

Re: Creating a dummy session

Post by Tomba » Sat Nov 02, 2013 3:19 pm

Here's what I did. Simple enough to save me the database overhead of storing the session, while still loading language an theme.

(after including common.php)

Code: Select all

$user->data['user_id'] = ANONYMOUS;
$user->setup();
For server rss feeds for instance this is perfect, as this gets hit numerously by bots an this prevents getting too many UPDATES on the phpbb_sessions table (which on heavy load creates a bottleneck).

Locked

Return to “[3.0.x] MOD Writers Discussion”