From c9145e8c18d9923467b74740a3aec6b4dd995866 Mon Sep 17 00:00:00 2001 From: Biser Perchinkov Date: Sun, 22 Jan 2023 14:23:03 -0500 Subject: [PATCH 1/2] Close active PHP Session if found when running a Dedicated Sync request, to make sure we're not locking the request unnecessarily. --- projects/packages/sync/src/class-sender.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/projects/packages/sync/src/class-sender.php b/projects/packages/sync/src/class-sender.php index 17822d18c08c9..9a7981a2ffb70 100644 --- a/projects/packages/sync/src/class-sender.php +++ b/projects/packages/sync/src/class-sender.php @@ -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(); From a45380e157e617b19c154d71bb42ca0d7f5c5a33 Mon Sep 17 00:00:00 2001 From: Biser Perchinkov Date: Sun, 22 Jan 2023 14:24:39 -0500 Subject: [PATCH 2/2] Add changelog --- .../sync/changelog/fix-sync-close-php-session-immediately | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/packages/sync/changelog/fix-sync-close-php-session-immediately diff --git a/projects/packages/sync/changelog/fix-sync-close-php-session-immediately b/projects/packages/sync/changelog/fix-sync-close-php-session-immediately new file mode 100644 index 0000000000000..4a055f39ca66c --- /dev/null +++ b/projects/packages/sync/changelog/fix-sync-close-php-session-immediately @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +Close PHP Session if it's active when running a Dedicated Sync request.