Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the torden branch of ngx_cache_purge #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion admin/class-fastcgi-purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function purge_url( $url, $feed = true ) {

case 'get_request':
// Go to default case.

case 'get_request_torden':
// Go to default case.

default:
$_url_purge_base = $this->purge_base_url() . $parse['path'];
$_url_purge = $_url_purge_base;
Expand Down Expand Up @@ -137,6 +141,10 @@ public function custom_purge_urls() {

case 'get_request':
// Go to default case.

case 'get_request_torden':
// Go to default case.

default:
$_url_purge_base = $this->purge_base_url();

Expand Down Expand Up @@ -166,7 +174,48 @@ public function custom_purge_urls() {
*/
public function purge_all() {

$this->unlink_recursive( RT_WP_NGINX_HELPER_CACHE_PATH, false );
global $nginx_helper_admin;

switch ( $nginx_helper_admin->options['purge_method'] ) {

case 'get_request_torden':
$site = get_site_url();
$find = [ 'http://', 'https://' ];
$replace = '';
$host = str_replace( $find, $replace, $site);

if ( is_ssl() ) {

$purgeurl = $site . '/purgeall' ;
$curl = curl_init( $purgeurl );
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PURGE" );
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_RESOLVE, array( $host . ":443:127.0.0.1" ));

} else {

$curl = curl_init( "http://127.0.0.1/purgeall" );
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Host:' . $host ));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PURGE" );
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);

}

$response = curl_exec($curl);
if ($response === false)
$this->log( curl_errno($curl) .': '. curl_error($curl) );
curl_close($curl);
break;

case 'get_request':
// Go to default case.

default:
$this->unlink_recursive( RT_WP_NGINX_HELPER_CACHE_PATH, false );
break;
}

$this->log( '* * * * *' );
$this->log( '* Purged Everything!' );
$this->log( '* * * * *' );
Expand Down
35 changes: 34 additions & 1 deletion admin/partials/nginx-helper-general-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,40 @@
sprintf(
// translators: %s Nginx cache purge module link.
__( 'Uses the %s module.', 'nginx-helper' ),
'<strong><a href="https://github.com/FRiCKLE/ngx_cache_purge">ngx_cache_purge</a></strong>'
'<strong><a href="https://github.com/FRiCKLE/ngx_cache_purge">ngx_cache_purge (FRiCKLE)</a></strong>'
),
array(
'strong' => array(),
'a' => array(
'href' => array(),
),
)
);
?>
</small>
</label>
<br />
<label for="purge_method_get_request_torden">
<input type="radio" value="get_request_torden" id="purge_method_get_request_torden" name="purge_method" <?php checked( $nginx_helper_settings['purge_method'], 'get_request_torden' ); ?>>
&nbsp;
<?php
echo wp_kses(
sprintf(
'%1$s <strong>PURGE/url</strong> %2$s',
esc_html__( 'Using a GET request to', 'nginx-helper' ),
esc_html__( '(Supports torden\'s `purge_all` method)', 'nginx-helper' )
),
array( 'strong' => array() )
);
?>
<br />
<small>
<?php
echo wp_kses(
sprintf(
// translators: %s Nginx cache purge module link.
__( 'Uses the %s module.', 'nginx-helper' ),
'<strong><a href="https://github.com/torden/ngx_cache_purge">ngx_cache_purge (torden)</a></strong>'
),
array(
'strong' => array(),
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== Nginx Helper ===
Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards, niwreg, entr, nuvoPoint, iam404, rittesh.patel, vishalkakadiya, BhargavBhandari90, vincent-lu, murrayjbrown, bryant1410, 1gor, matt-h, pySilver, johan-chassaing, dotsam, sanketio, petenelson, nathanielks, rigagoogoo, dslatten, jinschoi, kelin1003, vaishuagola27, rahulsprajapati, Joel-James, utkarshpatel, gsayed786, shashwatmittal, sudhiryadav, thrijith, stayallive, jaredwsmith, abhijitrakas, umeshnevase, sid177, souptik, arafatkn, subscriptiongroup
Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards, niwreg, entr, nuvoPoint, iam404, rittesh.patel, vishalkakadiya, BhargavBhandari90, vincent-lu, murrayjbrown, bryant1410, 1gor, matt-h, pySilver, johan-chassaing, dotsam, sanketio, petenelson, nathanielks, rigagoogoo, dslatten, jinschoi, kelin1003, vaishuagola27, rahulsprajapati, Joel-James, utkarshpatel, gsayed786, shashwatmittal, sudhiryadav, thrijith, stayallive, jaredwsmith, abhijitrakas, umeshnevase, sid177, souptik, arafatkn, subscriptiongroup, gnif
Donate Link: http://rt.cx/eedonate/
Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
License: GPLv2 or later (of-course)
Expand Down