Plugin Directory

Changeset 2155285


Ignore:
Timestamp:
09/12/2019 06:25:24 AM (6 years ago)
Author:
runcloud
Message:

added redis check connection

Location:
runcache-purger/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • runcache-purger/trunk/assets/runcache_purger.css

    r2154797 r2155285  
    526526}
    527527
    528 #runcachepurger-wrap .cache-redis {
    529     padding-left: 32px;
    530 }
    531 
    532528#runcachepurger-wrap .cache-redis > h4 {
    533529    margin-bottom: 5px;
     
    547543}
    548544
     545#runcachepurger-wrap .cache-redis > div.redis-status {
     546    display: inline-block;
     547    width: 60%;
     548    margin-top: 8px;
     549    padding: 8px 0 8px 0;
     550    height: 32px;
     551    color: #23282d;
     552    font-family: monospace, monaco, Consolas, Lucida Console;
     553    font-size: 14px;
     554    font-weight: 500;
     555    line-height: 1.33333;
     556}
     557
     558#runcachepurger-wrap .cache-redis > div.redis-status-ok {
     559    color: green;
     560}
     561
     562#runcachepurger-wrap .cache-redis > div.redis-status-ko {
     563    color: red;
     564}
     565
    549566@media (max-width: 783px) {
    550 
    551     #runcachepurger-wrap .cache-redis {
    552         padding-left: 0px;
    553     }
    554567
    555568    #runcachepurger-wrap .cache-redis > label {
  • runcache-purger/trunk/languages/runcachepurger.pot

    r2154797 r2155285  
    55msgstr  "Project-Id-Version: RunCache Purger 1.0.0\n"
    66        "Report-Msgid-Bugs-To: https://runcloud.io\n"
    7         "POT-Creation-Date: 2019-09-11 21:09+0800\n"
     7        "POT-Creation-Date: 2019-09-12 14:23+0800\n"
    88        "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    99        "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1414        "Content-Transfer-Encoding: 8bit\n"
    1515
    16 #: runcache-purger.php:253
     16#: runcache-purger.php:277
    1717#, php-format
    1818msgid   "The <strong>%1$s</strong> plugin version %2$s requires:"
    1919msgstr  ""
    2020
    21 #: runcache-purger.php:264
     21#: runcache-purger.php:288
    2222#, php-format
    2323msgid   "WordPress version %s or higher."
    2424msgstr  ""
    2525
    26 #: runcache-purger.php:273
     26#: runcache-purger.php:297
    2727#, php-format
    2828msgid   "PHP version %s or higher."
    2929msgstr  ""
    3030
    31 #: runcache-purger.php:281
     31#: runcache-purger.php:305
    3232msgid   "Apache or NGINX Web Server."
    3333msgstr  ""
    3434
    35 #: runcache-purger.php:287
     35#: runcache-purger.php:311
    3636msgid   "The plugin has now deactivated itself. Please contact your hosting "
    3737        "provider or system administrator for version upgrade."
    3838msgstr  ""
    3939
    40 #: runcache-purger.php:516 runcache-purger.php:635
     40#: runcache-purger.php:544 runcache-purger.php:663
    4141msgid   "Settings"
    4242msgstr  ""
    4343
    44 #: runcache-purger.php:650
     44#: runcache-purger.php:678
    4545msgid   "Clear Cache this Post"
    4646msgstr  ""
    4747
    48 #: runcache-purger.php:661
     48#: runcache-purger.php:689
    4949msgid   "Clear Cache this URL"
    5050msgstr  ""
    5151
    52 #: runcache-purger.php:671 views/settings.php:191
     52#: runcache-purger.php:699 views/settings.php:194
    5353msgid   "Clear All Cache"
    5454msgstr  ""
    5555
    56 #: runcache-purger.php:1096
     56#: runcache-purger.php:1124
    5757msgid   "Failed to purge cache."
    5858msgstr  ""
    5959
    60 #: runcache-purger.php:1103
     60#: runcache-purger.php:1131
    6161msgid   "Purging cache was successful."
    6262msgstr  ""
    6363
    64 #: runcache-purger.php:1105
     64#: runcache-purger.php:1133
    6565msgid   "Purging redis object cache was successful."
    6666msgstr  ""
    6767
    68 #: runcache-purger.php:1110
     68#: runcache-purger.php:1138
    6969#, php-format
    7070msgid   "Purging method not implement. Status Code %s"
    7171msgstr  ""
    7272
    73 #: runcache-purger.php:1114
     73#: runcache-purger.php:1143
     74msgid   "Redis server not connected."
     75msgstr  ""
     76
     77#: runcache-purger.php:1145
    7478msgid   "Failed to purge redis object cache."
    7579msgstr  ""
    7680
    77 #: runcache-purger.php:1116
     81#: runcache-purger.php:1148
    7882msgid   "Purging method not implement."
    7983msgstr  ""
    8084
    81 #: runcache-purger.php:1121
     85#: runcache-purger.php:1153
    8286#, php-format
    8387msgid   "Failed to purge cache. Status Code %s"
     
    165169msgstr  ""
    166170
    167 #: views/settings.php:145
     171#: views/settings.php:143
     172msgid   "Status"
     173msgstr  ""
     174
     175#: views/settings.php:147
     176msgid   "Hostname"
     177msgstr  ""
     178
     179#: views/settings.php:150
     180msgid   "Port"
     181msgstr  ""
     182
     183#: views/settings.php:153
     184msgid   "Key Prefix"
     185msgstr  ""
     186
     187#: views/settings.php:160
    168188msgid   "Purge Object Cache"
    169189msgstr  ""
    170190
    171 #: views/settings.php:149
     191#: views/settings.php:164
    172192msgid   "Automatically clean redis object cache when any purge action was "
    173193        "triggered."
    174194msgstr  ""
    175195
    176 #: views/settings.php:156
     196#: views/settings.php:171
    177197msgid   "Enable Object Cache"
    178198msgstr  ""
    179199
    180 #: views/settings.php:160
     200#: views/settings.php:175
    181201msgid   "Enable this option to allow this plugin handle redis object cache."
    182202msgstr  ""
    183203
    184 #: views/settings.php:166
    185 msgid   "Hostname"
    186 msgstr  ""
    187 
    188 #: views/settings.php:169
    189 msgid   "Port"
    190 msgstr  ""
    191 
    192 #: views/settings.php:172
    193 msgid   "Key Prefix"
    194 msgstr  ""
    195 
    196 #: views/settings.php:186
     204#: views/settings.php:189
    197205msgid   "Purge Actions"
    198206msgstr  ""
    199207
    200 #: views/settings.php:195
     208#: views/settings.php:198
    201209msgid   "Clear Homepage Cache"
    202210msgstr  ""
    203211
    204 #: views/settings.php:199
     212#: views/settings.php:202
    205213msgid   "Clear Content Cache"
    206214msgstr  ""
    207215
    208 #: views/settings.php:203
     216#: views/settings.php:206
    209217msgid   "Clear Archives Cache"
    210218msgstr  ""
    211219
    212 #: views/settings.php:207
     220#: views/settings.php:210
    213221msgid   "Clear Redis Cache"
    214222msgstr  ""
  • runcache-purger/trunk/runcache-purger.php

    r2155198 r2155285  
    4444define('RUNCACHE_PURGER_PATH_LANG', RUNCACHE_PURGER_PATH . 'languages/');
    4545define('RUNCACHE_PURGER_PATH_VIEW', RUNCACHE_PURGER_PATH . 'views/');
     46!defined('RUNCACHE_PURGER_PATH_VENDOR') && define('RUNCACHE_PURGER_PATH_VENDOR', RUNCACHE_PURGER_PATH . 'vendor/');
    4647
    4748final class RunCache_Purger
     
    172173        if (false !== strpos($_SERVER['SERVER_SOFTWARE'], 'nginx')) {
    173174            return true;
     175        }
     176
     177        return false;
     178    }
     179
     180    /**
     181     * is_redis_connect.
     182     */
     183    private static function is_redis_connect($host = null, $port = null, &$error = '')
     184    {
     185
     186        if ( function_exists('__redis_is_connect') ) {
     187            if ( empty($host) || empty($port) ) {
     188                $options = self::get_settings();
     189                $host = $options['redis_host'];
     190                $port = $options['redis_port'];
     191            }
     192            if ( __redis_is_connect($host, $port, $error) ) {
     193                return true;
     194            }
    174195        }
    175196
     
    200221    public static function register()
    201222    {
     223
     224        require_once RUNCACHE_PURGER_PATH_VENDOR . 'redis_is_connect.php';
     225
    202226        self::register_locale();
    203227
     
    11161140                    if ( !empty($req_status['is_redis']) && 404 === $req_status['code'] ) {
    11171141                        if ( !empty($req_status['is_avail']) ) {
    1118                             $msg = __('Failed to purge redis object cache.', self::$textdomain);
     1142                            if ( !empty($req_status['is_avail']) ) {
     1143                                $msg = __('Redis server not connected.', self::$textdomain);
     1144                            } else {
     1145                                $msg = __('Failed to purge redis object cache.', self::$textdomain);
     1146                            }
    11191147                        } else {
    11201148                            $msg = __('Purging method not implement.', self::$textdomain);
     
    11991227     */
    12001228    public static function flush_object($purge = false) {
    1201         $ok = wp_cache_flush();
     1229        $ok = false;
    12021230        $filesave = WP_CONTENT_DIR.'/object-cache.php';
    12031231        $is_avail = ( file_exists($filesave) ? true : false );
     1232        $is_connect = self::is_redis_connect(null, null, $redis_error);
     1233
     1234        if ( $is_connect ) {
     1235            $ok = wp_cache_flush();
     1236        }
     1237
    12041238        $return = [
    12051239            'code' => ( $ok ? 200 : 404 ),
    12061240            'is_redis' => 1,
    1207             'is_avail' => ( $is_avail ? 1 : 0 )
     1241            'is_avail' => ( $is_avail ? 1 : 0 ),
     1242            'is_connect' => ( $is_connect ? 1 : 0 )
    12081243        ];
     1244
     1245        if ( !$is_connect && !empty($redis_error) ) {
     1246            $return['is_connect_error'] = $redis_error; 
     1247        }
    12091248
    12101249        if ( !$purge ) {
  • runcache-purger/trunk/vendor/object-cache.php

    r2155196 r2155285  
    1111define('RUNCACHE_PURGER_DROPIN', true);
    1212!defined('WP_REDIS_SELECTIVE_FLUSH') && define('WP_REDIS_SELECTIVE_FLUSH', true);
     13!defined('RUNCACHE_PURGER_PATH_VENDOR') && define('RUNCACHE_PURGER_PATH_VENDOR', ( defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins/runcache-purger/vendor/' ) );
    1314
    1415/*@CONFIG-MARKER@*/
     16
     17function wp_cache_is_redis_connect()
     18{
     19    static $__redis_is_connect = false;
     20
     21    if ( $__redis_is_connect ) {
     22        return true;
     23    }
     24
     25    if ( !function_exists('__redis_is_connect') && defined('RUNCACHE_PURGER_DROPIN_HOST') && defined('RUNCACHE_PURGER_DROPIN_PORT') ) {
     26        $file = RUNCACHE_PURGER_PATH_VENDOR.'redis_is_connect.php';
     27        if ( file_exists($file) ) {
     28            include_once($file);
     29
     30            if ( function_exists('__redis_is_connect') ) {
     31                if ( __redis_is_connect(RUNCACHE_PURGER_DROPIN_HOST, RUNCACHE_PURGER_DROPIN_PORT) ) {
     32                    $__redis_is_connect = true;
     33                    return true;
     34                }
     35            }
     36        }
     37    }
     38
     39    $__redis_is_connect = false;
     40    return false;
     41}
     42
     43if ( wp_cache_is_redis_connect() ):
    1544
    1645function wp_cache_add($key, $value, $group = '', $expiration = 0)
     
    248277
    249278                if (! class_exists('Predis\Client')) {
    250                     $predis = sprintf(
    251                         '%s/runcache-purger/vendor/predis/autoload.php',
    252                         defined('WP_PLUGIN_DIR') ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'
    253                     );
     279                    $predis = RUNCACHE_PURGER_PATH_VENDOR.'predis/autoload.php';
    254280
    255281                    if (file_exists($predis)) {
     
    926952}
    927953
    928 endif;
     954endif; // is_redis_connect
     955endif; // if defined
  • runcache-purger/trunk/views/settings.php

    r2154691 r2155285  
    139139
    140140                        <fieldset class="runcachepurger-field-container-fieldset">
    141 
    142                             <div class="runcachepurger-field runcachepurger-field-checkbox">
    143                                 <div class="runcachepurger-checkbox">
    144                                     <input type="checkbox" id="redis_purge_onn" name="<?php self::view_fname('redis_purge_onn');?>" value="1"<?php self::view_checked('redis_purge_onn');?>>
    145                                     <label for="redis_purge_onn"><?php _e( 'Purge Object Cache', self::$textdomain ); ?></label>
    146                                 </div>
    147 
    148                                 <div class="runcachepurger-field-description">
    149                                     <?php _e( 'Automatically clean redis object cache when any purge action was triggered.', self::$textdomain ); ?>
    150                                 </div>
    151                             </div>
    152 
    153                             <div class="runcachepurger-field runcachepurger-field-checkbox">
    154                                 <div class="runcachepurger-checkbox">
    155                                     <input type="checkbox" id="redis_cache_onn" name="<?php self::view_fname('redis_cache_onn');?>" value="1"<?php self::view_checked('redis_cache_onn');?>>
    156                                     <label for="redis_cache_onn"><?php _e( 'Enable Object Cache', self::$textdomain ); ?></label>
    157                                 </div>
    158 
    159                                 <div class="runcachepurger-field-description">
    160                                     <?php _e( 'Enable this option to allow this plugin handle redis object cache.', self::$textdomain ); ?>
    161                                 </div>
    162                             </div>
    163 
    164141                            <div class="runcachepurger-field cache-redis">
    165142                                <h4>Redis Server</h4>
     143                                <label for="redis_prefix"><?php _e( 'Status', self::$textdomain ); ?></label>
     144                                <?php $redis_stat = self::is_redis_connect(self::$value['redis_host'], self::$value['redis_port']); ?>
     145                                <div class='redis-status<?php echo ( $redis_stat ? ' redis-status-ok' : ' redis-status-ko');?>'><?php echo ( $redis_stat ? 'Connected' : 'Not connected' );?></div>
     146                                <br>
    166147                                <label for="redis_host"><?php _e( 'Hostname', self::$textdomain ); ?></label>
    167148                                <input type="text" id="redis_host" name="<?php self::view_fname('redis_host');?>" value="<?php self::view_fvalue('redis_host');?>">
     
    172153                                <label for="redis_prefix"><?php _e( 'Key Prefix', self::$textdomain ); ?></label>
    173154                                <input type="text" id="redis_prefix" name="<?php self::view_fname('redis_prefix');?>" value="<?php self::view_fvalue('redis_prefix');?>">
     155                            </div>
     156
     157                            <div class="runcachepurger-field runcachepurger-field-checkbox">
     158                                <div class="runcachepurger-checkbox">
     159                                    <input type="checkbox" id="redis_purge_onn" name="<?php self::view_fname('redis_purge_onn');?>" value="1"<?php self::view_checked('redis_purge_onn');?>>
     160                                    <label for="redis_purge_onn"><?php _e( 'Purge Object Cache', self::$textdomain ); ?></label>
     161                                </div>
     162
     163                                <div class="runcachepurger-field-description">
     164                                    <?php _e( 'Automatically clean redis object cache when any purge action was triggered.', self::$textdomain ); ?>
     165                                </div>
     166                            </div>
     167
     168                            <div class="runcachepurger-field runcachepurger-field-checkbox">
     169                                <div class="runcachepurger-checkbox">
     170                                    <input type="checkbox" id="redis_cache_onn" name="<?php self::view_fname('redis_cache_onn');?>" value="1"<?php self::view_checked('redis_cache_onn');?>>
     171                                    <label for="redis_cache_onn"><?php _e( 'Enable Object Cache', self::$textdomain ); ?></label>
     172                                </div>
     173
     174                                <div class="runcachepurger-field-description">
     175                                    <?php _e( 'Enable this option to allow this plugin handle redis object cache.', self::$textdomain ); ?>
     176                                </div>
    174177                            </div>
    175178
Note: See TracChangeset for help on using the changeset viewer.