R
R
r1ch2013-12-03 23:21:29
PHP
r1ch, 2013-12-03 23:21:29

Difference between sessions and session emulation?

While in theory, so I can not make a benchmark
1) Sessions - are stored in the tmp folder as files inside which are, and sql queries and html, and service data.
2)

CREATE TABLE `admin` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `login` VARCHAR(40) NOT NULL,
  `pass` VARCHAR(40) NOT NULL,
  `hash` CHAR(40) ,
  PRIMARY KEY (id),
  UNIQUE  login_unq(login),
  UNIQUE  hash_unq(hash)
);

Session emulation using cookies and a table, in the admin table there is a hash value for the identifier (similar to session_id), and it is possible to write this hash to the cookie, and when you enter, refresh the page, generate a new hash and write it to the cookie, delete cookies on exit, otherwise, it will leave itself after a specified time.
1) Expected session problems: what if 1 million visitors will have 1 million files whose average size is from 25 to 56 kb, which gives a memory consumption of 25.8 GB to 53.4 GB
Pros of sessions: convenient, there are functions to work with.
2) Expected problems of session emulation: many queries to the database,
Pluses of session emulation: the memory in the database is equal, one hash CHAR (40) is equal to 40 bytes, which is 38.1 mb per 1 million.
Security issue: if the database is pulled, they can use hash by substituting it in their cookies. Possible solution: write the converted to sha1(hash) in the database, only the hash itself in the cookie, convert the hash from the cookie to sha1 for comparison with the values ​​from the database.
I may be wrong somewhere...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vit, 2013-12-04
@r1ch

Sessions in files are fu: there can be problems with locks (here I wrote about this toster.ru/q/54276#answer_198530 ) + this option does not scale. Although for a small site, the option on files is quite suitable.
I switched to storing the session in a sql or nosql database a long time ago.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question