Created
August 30, 2019 10:29
-
-
Save SauntValerian/f90026441fe250a53807b88884ae8e1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Opcache integration class. | |
* | |
* @since 2.1.0 | |
* @package Hummingbird\Core\Integration | |
*/ | |
namespace Hummingbird\Core\Integration; | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
/** | |
* Class Opcache | |
*/ | |
class Opcache { | |
/** | |
* Opcache constructor. | |
* | |
* @since 2.1.0 | |
*/ | |
public function __construct() { | |
if ( ! $this->is_enabled() ) { | |
return; | |
} | |
add_action( 'wphb_clear_cache_url', array( $this, 'purge_cache' ) ); | |
} | |
/** | |
* Check if opcache is enabled on the server. | |
* | |
* @since 2.1.0 | |
* @return bool | |
*/ | |
public function is_enabled() { | |
if ( ! function_exists( 'opcache_get_status' ) ) { | |
return false; | |
} | |
$opcache = opcache_get_status(); | |
if ( isset( $opcache['opcache_enabled'] ) ) { | |
return $opcache['opcache_enabled']; | |
} | |
return false; | |
} | |
/** | |
* Purge cache. | |
* | |
* @since 2.1.0 | |
* | |
* @param string $path Path to purge for. | |
*/ | |
public function purge_cache( $path = '' ) { | |
// Only purge when full cache is cleared. | |
if ( ! empty( $path ) ) { | |
return; | |
} | |
if ( ! function_exists( 'opcache_reset' ) ) { | |
return; | |
} | |
$status = opcache_reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment