J
J
John Didact2020-04-28 19:00:13
PHP
John Didact, 2020-04-28 19:00:13

When is session data serialized and written to a file?

Here I have two questions...
1. In what cases is the data from the session serialized and written to a file? If you specify an option in session_start() to ensure that the file is not blocked, then the data from the session file is simply read, deserialized and written to the $_SESSION array. If this option is not specified, the data from the file is read and the file is locked. After the script ends or when it is called session_write_close(), the data is serialized, written to the file, and it will be unlocked. So, if the data is not changed (is it tracked somehow?), then the file will still be overwritten or not?
2. Is it advisable or not to compare arrays and if the arrays are different, then write data from one array to another? For example, how will it be less resource intensive if the arrays are more often the same than different?

$_SESSION['user'] === $this->user or $_SESSION['user'] = $this->user;
$_SESSION['client'] === $this->client or $_SESSION['client'] = $this->client;
// ...
or
$_SESSION = array(
 'user' => $this->user,
 'client' => $this->client,
 // ...
);


UPD. $_SESSION['user'], $_SESSION['client'], $this->user, $this->client- contain arrays of data.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2020-04-28
@JohnDidact

1. Must be overwritten
2. Doesn't matter. You can do either this or that. Or this way and that.
The operation itself is kind of pointless. No need to store objects in the session. You can store a couple of attributes in the session that are injected into the object upon creation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question