Page 1 of 1

Creating a dummy session

Posted: Mon Oct 14, 2013 6:54 pm
by Tomba
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?

Re: Creating a dummy session

Posted: Tue Oct 15, 2013 2:17 am
by EXreaction
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?

Re: Creating a dummy session

Posted: Tue Oct 15, 2013 8:13 pm
by Tomba
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.

Re: Creating a dummy session

Posted: Tue Oct 15, 2013 11:40 pm
by EXreaction
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.

Re: Creating a dummy session

Posted: Sat Nov 02, 2013 3:19 pm
by Tomba
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;
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).