Skip to content
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

Fix/sync close php session immediately #28515

Merged
merged 2 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Close PHP Session if it's active when running a Dedicated Sync request.
18 changes: 18 additions & 0 deletions projects/packages/sync/src/class-sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,24 @@ public function do_dedicated_sync_and_exit( $do_real_exit = true ) {
// Try to disconnect the request as quickly as possible and process things in the background.
$this->fastcgi_finish_request();

/**
* Close the PHP session to free up the server threads to handle other requests while we
* send sync data with Dedicated Sync.
*
* When we spawn Dedicated Sync, we send `$_COOKIES` with the request to help out with any
* firewall and/or caching functionality that might prevent us to ping the site directly.
*
* This will cause Dedicated Sync to reuse the visitor's PHP session and lock it until the
* request finishes, which can take anywhere from 1 to 30+ seconds, depending on the server
* `max_execution_time` configuration.
*
* By closing the session we're freeing up the session, so other requests can acquire the
* lock and proceed with their own tasks.
*/
if ( session_status() === PHP_SESSION_ACTIVE ) {
session_write_close();
}

// Output not used right now. Try to release dedicated sync lock
Dedicated_Sender::try_release_lock_spawn_request();

Expand Down