Plugin Directory

Changeset 1022567


Ignore:
Timestamp:
11/09/2014 07:31:37 PM (10 years ago)
Author:
mlazarov
Message:

Adding max load average default value according to cpu's count

Location:
hyper-cache-extended/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • hyper-cache-extended/trunk/cache.php

    r629177 r1022567  
    2525    return false;
    2626}
     27
     28if(!$hyper_cache['load']){$hyper_cache['load'] = 5;}
     29
     30
     31$loadavg = explode(' ',@file_get_contents('/proc/loadavg'));
     32$server_load = (float)$loadavg[0];
     33
     34
    2735
    2836$hyper_uri = $_SERVER['REQUEST_URI'];
     
    8593// Do not use or cache pages when a wordpress user is logged on
    8694foreach ($_COOKIE as $n => $v) {
    87     // If it's required to bypass the cache when the visitor is a commenter, stop.
    88     if ($hyper_cache['comment'] && substr($n, 0, 15) == 'comment_author_')
     95    // If it's required to bypass the cache when the visitor is a commenter AND server load is bellow critical, stop.
     96    if ($hyper_cache['comment'] && substr($n, 0, 15) == 'comment_author_' && $server_load < $hyper_cache['load'])
    8997        return false;
    9098
     
    116124    return;
    117125}
    118 
    119 if(!$hyper_cache['load']) $hyper_cache['load'] = 5;
    120 
    121 $loadavg = explode(' ',@file_get_contents('/proc/loadavg'));
    122 $server_load = (float)$loadavg[0];
    123126
    124127$hc_file_time = @ filemtime($hc_file);
  • hyper-cache-extended/trunk/options.php

    r923973 r1022567  
    190190    </td>
    191191</tr>
    192 
     192<?php
     193$numCpus = false;
     194if (is_file('/proc/cpuinfo') && is_readable('/proc/cpuinfo')){
     195    $cpuinfo = file_get_contents('/proc/cpuinfo');
     196    preg_match_all('/^processor/m', $cpuinfo, $matches);
     197    $numCpus = count($matches[0]);
     198}
     199
     200?>
    193201
    194202<tr valign="top">
     
    197205        <input type="text" size="5" name="options[load]" value="<?php echo htmlspecialchars($options['load']); ?>"/>
    198206        <br />
    199         <?php _e('Hyper Cache Extended will serve the cached pages until Server Load gets below this number', 'hyper-cache');?>
     207        <?php _e('Hyper Cache Extended will serve the cached pages until Server Load gets below this number. '.($numCpus?'Optimal value: '.($numCpus+1):''), 'hyper-cache');?>
    200208    </td>
    201209</tr>
  • hyper-cache-extended/trunk/plugin.php

    r923973 r1022567  
    4343function hyper_activate(){
    4444    $hce_options = get_option('hyper_cache_extended');
     45
    4546
    4647    $options = array();
     
    5758    $options['expire_type'] = 'post';
    5859    $options['path'] = WP_CONTENT_DIR.'/cache/';
     60
     61    if (is_file('/proc/cpuinfo') && is_readable('/proc/cpuinfo')){
     62        $cpuinfo = file_get_contents('/proc/cpuinfo');
     63        preg_match_all('/^processor/m', $cpuinfo, $matches);
     64        $numCpus = count($matches[0]);
     65        $options['load'] = $numCpus + 1;
     66    }
     67   
    5968
    6069    $buffer = hyper_generate_config($options);
Note: See TracChangeset for help on using the changeset viewer.