Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of session_abort()

I have been checking the PHP session functions and I saw session_abort().

  • What is the purpose of using session_abort()?

  • What is the difference between session_abort() and session_destroy()?

like image 462
Pooya sanaei Avatar asked Sep 14 '15 13:09

Pooya sanaei


2 Answers

session_abort() is analogous to session_write_close().

PHP locks session data during a web request to prevent data corruption on multiple simultaneous requests.

When Request 1 comes in, Session 1 is locked by that process so it can make any changes needed. If Request 2 comes in for Session 1, php blocks until the session lock is released to make sure that Request 2 has the most up-to-date session data.

session_abort() closes the session and releases the lock without flushing session data to the session storage mechanism while session_write_close() writes the current content of session back and then closes / releases the lock.

edit: Calling session_abort() or session_write_close() will let php process Request 2 even if Request 1 is not finished processing.

like image 147
Josh J Avatar answered Oct 21 '22 23:10

Josh J


session_abort() finishes session without saving data. Thus the original values in session data are kept.

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

References :

http://php.net/manual/en/function.session-destroy.php

http://php.net/manual/en/function.session-abort.php

like image 37
Amit Horakeri Avatar answered Oct 21 '22 21:10

Amit Horakeri