Create a global session for all users

I use php 5.4.

Session variables $_SESSION['name']are used to store data, so the data can be accessed in any future request, but unique to the user.

Is it possible to create something similar to the session variable, accessible for the entire incoming request, but no matter what user it is there is? In other words, a session variable that is not unique to users

I currently use MySQL db to store temporary data, but I think that if this Global Session for all usersis possible it will give some performance improvement

I want to store something very small, like 4- significant number

+4
source share
4 answers

By default, session data is serializedstored in a temporary file associated with the user's session, which is tracked by the cookie. You can also configure session data to save to the database. This data is available through $_SESSIONsuperglobal for each user.

So, if you follow this logic, then either store the serializeddata in a file, or store it in a database and to access it, it will not be superglobal, but something will be almost superglobal if you read it as a global array, such as $GLOBALS['all_peeps'].

. , , .

+3

wikipedia:

- (...) .

, , , session. .

, - , ( php- [ ]).

+1

GLOBAL.

  • , 4- var. , ( , i.e.).

  • - MySQL... - SQLite.

  • , .

:

$fp = fopen("variable_name.txt", "w");
fwrite($fp, $value); // $value is the 4 digit value you wish to store.
fclose($fp);

:

$fp = fopen("variable_name.txt", "r");

$value = fread($fp, 1024);

fclose($fp);

/ ... .

0

, . ?

: - . . , , . ( )

, , . .

If you are using a database for the global season, if there is only one piece of data in the session, this should be good, as the database will ensure that there is no incomplete temporary state. If there is more than one piece of data in a season and they are related to each other, you should use the database transaction functions to ensure that they are in the correct state in all cases.

0
source

Source: https://habr.com/ru/post/1531975/


All Articles