-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sessions #976
Open
mt-omarov
wants to merge
62
commits into
VKCOM:master
Choose a base branch
from
mt-omarov:sessions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sessions #976
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Define session class. 2. Define the basic structure of the basic functions. 3. Write the abstract logic of reading and writing session files with the stream and serialize functions.
…functions and simple logic for working with extra attributes for session files.
- add aliases with macros: getxattr(), setxattr() -> get_tag(), set_tag(), - change flock() -> fcntl() with F_SETLKW, - add an additional check for the validity of file descriptor in session_close()
- session_id(), - session_start(), - session_status()
…nto andreylzmw/runtime_light_ci
- add the resetting logic of fd before deleting files from dir, - change mode of session files from 0777 to 0666, - add new tag to filter session files from other files in session_gc().
nevermort
previously approved these changes
Jul 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sessions
This PR adds a simple implementation of php sessions in KPHP.
Implemented functions
session_start()
session_abort()
session_commit()
session_write_close()
session_gc()
session_status()
session_encode()
session_decode()
session_get_cookie_params()
session_id()
session_reset()
session_unset()
Supported options
save_path
name
gc_probability
gc_divisor
gc_maxlifetime
cookie_lifetime
cookie_path
cookie_domain
cookie_secure
cookie_httponly
cookie_samesite
use_strict_mode
sid_length
lazy_write
Problems
A simple implementation should avoid handling interprocessor states. This means that the standard ways of storing variables in a cpp file cannot be used.
It is possible situation of simultaneous attempt to write/read one session from different requests. This means that it is necessary to queue such workers in some way, as php also does.
The difficulty of deleting files follows from the problem above, since it is important to avoid locking workers.
Solutions and methods
Using superglobals to store session states within a single worker. Variables such as v$_COOKIE have their own memory per worker, so an additional array created using the same rules as v$_SESSION is used to avoid inter-processor states.
The
lockf()
function with exclusive blockingF_LOCK
is used to block workers.Еo avoid unnecessary reading of certain data from files, tags (
getxattr
,setxattr
) from<sys/xattr.h>
are used that store frequently used information in the form of metadata to the file. Tags are used to store the life duration of the session (gc_maxlifetime
) and the status of the confirmation that the document is a session (to distinguish the session from other documents).To generate a reliable sequence of a given length
random_bytes()
is used together withbin2hex()
.Tests
To test the blocking of workers as processes with multiple requests to a single file, the php project JobWorkers from kphp-snippets is used. The test results are located on a separate branch in the form of github action test.
Confirmation of the blocking of workers can be seen in the sections
Send a request to the server
andRead logs
.Tests were written to demonstrate the correct operation of individual functions.
TO-DO
headers_sent
(https://www.php.net/manual/en/function.headers-sent.php)session_destroy(), session_sek_cookie_params(), session_register_shutdown(), session_regenerate_id(), session_create_id()
session_start()
is called