Cloudflare.php
1 year ago
Fastly.php
1 year ago
LiteSpeed.php
1 year ago
NestifyCDN.php
1 year ago
NginxFastCgi.php
1 year ago
Sucuri.php
1 year ago
NestifyCDN.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Server; |
| 4 | |
| 5 | /* Purge Nestify CDN cache on NitroPack purge cache */ |
| 6 | |
| 7 | class NestifyCDN { |
| 8 | const STAGE = "very_early"; |
| 9 | public function init( $stage ) { |
| 10 | if ( defined( 'NESTIFY_CDN_SITE_ID' ) ) { |
| 11 | add_action( 'nitropack_execute_purge_url', [ $this, 'log_purge_action' ], 10, 1 ); |
| 12 | add_action( 'nitropack_execute_purge_all', [ $this, 'log_purge_action' ], 10, 1 ); |
| 13 | } |
| 14 | } |
| 15 | /* Purge Nestify CDN cache on NitroPack purge cache. Used in WordPress Plugin called CDN Cache Helper */ |
| 16 | public function log_purge_action( $url = 'all' ) { |
| 17 | static $files = array(); |
| 18 | static $shutdown_hook_registered = false; |
| 19 | |
| 20 | if ( $url !== '' ) { |
| 21 | $files[] = $url; |
| 22 | } |
| 23 | |
| 24 | if ( ! $shutdown_hook_registered ) { |
| 25 | try { |
| 26 | $siteConfig = nitropack_get_site_config(); |
| 27 | if ( $siteConfig && ! empty( $siteConfig['home_url'] ) ) { |
| 28 | $data = array( 'url' => $_SERVER['HTTP_HOST'], 'files' => $files ); |
| 29 | $cdn_url = 'https://my.nestify.io/cdn/purge/' . NESTIFY_CDN_SITE_ID . '/purge'; |
| 30 | $client = new \NitroPack\HttpClient\HttpClient( $cdn_url ); |
| 31 | $client->setHeader( "Accept", "application/json" ); |
| 32 | $client->setHeader( "Content-Type", "application/json" ); |
| 33 | $client->setPostData( json_encode( $data ) ); |
| 34 | $client->timeout = 5; |
| 35 | $client->fetch( false, "POST" ); |
| 36 | } |
| 37 | |
| 38 | } catch (\Exception $e) { |
| 39 | |
| 40 | error_log( ' Exception: ' . $e->getMessage() ); |
| 41 | } |
| 42 | $shutdown_hook_registered = true; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 |