Skip to content

Commit

Permalink
Use fastcgi_finish_request is available on shutdown updates, closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredatch committed Apr 12, 2019
1 parent 82cd308 commit 89d3ad8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file, formatted v
- Admin bar stats.
- Support for Twitter counts using TwitCount.com, props @robert-gillmer.
- Automatic social share tracking with Google Analytics.
- Add support for `fastcgi_finish_request` when updating counts.

### Changed
- Pass post_id to `needs_updating` method.
Expand Down
19 changes: 18 additions & 1 deletion includes/class-shared-counts-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct() {

add_action( 'wp_ajax_shared_counts_email', [ $this, 'email_ajax' ] );
add_action( 'wp_ajax_nopriv_shared_counts_email', [ $this, 'email_ajax' ] );
add_action( 'shutdown', [ $this, 'update_share_counts' ] );
add_action( 'shutdown', [ $this, 'shutdown_update_share_counts' ] );
}

/**
Expand Down Expand Up @@ -817,6 +817,23 @@ public function update_share_counts() {
}
}

/**
* Update share counts on shutdown, after intial page rendering is complete.
*
* @since 1.3.0
*/
public function shutdown_update_share_counts() {

// If fastcgi_finish_request is available, run it which will close to
// browsers connection but allow the processing to continue in the
// background.
if ( function_exists( 'fastcgi_finish_request' ) ) {
fastcgi_finish_request();
}

$this->update_share_counts();
}

/**
* Prime the pump.
*
Expand Down

0 comments on commit 89d3ad8

Please sign in to comment.