Skip to content

Commit 89d3ad8

Browse files
committed
Use fastcgi_finish_request is available on shutdown updates, closes #12
1 parent 82cd308 commit 89d3ad8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file, formatted v
77
- Admin bar stats.
88
- Support for Twitter counts using TwitCount.com, props @robert-gillmer.
99
- Automatic social share tracking with Google Analytics.
10+
- Add support for `fastcgi_finish_request` when updating counts.
1011

1112
### Changed
1213
- Pass post_id to `needs_updating` method.

includes/class-shared-counts-core.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct() {
4444

4545
add_action( 'wp_ajax_shared_counts_email', [ $this, 'email_ajax' ] );
4646
add_action( 'wp_ajax_nopriv_shared_counts_email', [ $this, 'email_ajax' ] );
47-
add_action( 'shutdown', [ $this, 'update_share_counts' ] );
47+
add_action( 'shutdown', [ $this, 'shutdown_update_share_counts' ] );
4848
}
4949

5050
/**
@@ -817,6 +817,23 @@ public function update_share_counts() {
817817
}
818818
}
819819

820+
/**
821+
* Update share counts on shutdown, after intial page rendering is complete.
822+
*
823+
* @since 1.3.0
824+
*/
825+
public function shutdown_update_share_counts() {
826+
827+
// If fastcgi_finish_request is available, run it which will close to
828+
// browsers connection but allow the processing to continue in the
829+
// background.
830+
if ( function_exists( 'fastcgi_finish_request' ) ) {
831+
fastcgi_finish_request();
832+
}
833+
834+
$this->update_share_counts();
835+
}
836+
820837
/**
821838
* Prime the pump.
822839
*

0 commit comments

Comments
 (0)