• Resolved yydevelopment

    (@yydevelopment)


    Hi, i have few plugins I developed and a lot of custom code i created myself.

    Is there a way for me to run php function and clear your cache without the button on the top bar?
    Also is there a CLI command that allow to do that as well?

    Will be great if it’s possible for regular cache and cloudflare cache.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • If you want to purge the cache created by the plugin:

    <?php
    $tag = substr(md5(__DIR__ . '/system/library/lscache'),0,4);
    header("X-LiteSpeed-Purge:" . $tag);
    

    If you want to purge the entire cache:

    <?php
    header("X-LiteSpeed-Purge:*");

    To purge the cache only from CLI:

    if (php_sapi_name() === 'cli') {
    $path = dirname(__FILE__);
    $tag = __DIR__ . '/wp-content/plugins/litespeed-cache/';
    $tag = substr(md5($tag), -3) . '_';
    header("X-LiteSpeed-Purge:" . $tag);
    }else{
    header('HTTP/1.0 403 Forbidden');
    $contents = file_get_contents($path . '/403.shtml', TRUE);
    exit($contents);
    }

    403.shtml

    <!DOCTYPE html>
    <html style="height:100%">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" >
    <title> 403 Forbidden
    </title></head>
    <body style="color: #444; margin:0;font: normal 14px/20px Arial, Helvetica, sans-serif; height:100%; background-color: #fff;">
    <div style="height:auto; min-height:100%; ">     
    <div style="text-align: center; width:800px; margin-left: -400px; position:absolute; top: 30%; left:50%;"><h1 style="margin:0; font-size:150px; line-height:150px; font-weight:bold;">403</h1>
    <h2 style="margin-top:20px;font-size: 30px;">Forbidden</h2>
    <p>Access to this resource on the server is denied!</p>
    </div>
    </div>
    </body>
    </html>

    Copy the code from above into a blank PHP file and place it in document_root.

    • This reply was modified 2 years, 4 months ago by serpentdriver.
    Plugin Support qtwrk

    (@qtwrk)

    <?php
    require( './wp-load.php' );
    if ( defined('LSCWP_V')) {
      do_action( 'litespeed_purge_all' );
      echo 'done';
    }

    can use this one , it will call plugin’s purge API

    Thread Starter yydevelopment

    (@yydevelopment)

    Thanks for both of you,
    I sometimes update the sites via SSH,

    Is there a command i can use there as well to clear everything or does it require access to php and wp-load.php?

    Also does do_action( ‘litespeed_purge_all’ ); clear cloudflare as well?
    Does the api code offer a way to clear cloudflare as well or only the plugin cache?

    Plugin Support qtwrk

    (@qtwrk)

    you can run rm -rf /path/to/your/lscache/ but not suggested , as rm command is always dangerous

    it is better to use do_action( ‘litespeed_purge_all’ ); as it also clears object cache , generated JS/CSS files …etc

    no , it doesn’t purge CF

    Thread Starter yydevelopment

    (@yydevelopment)

    Thank you and sorry about the late reply.
    So just making sure, is there an action i can use to clear cloudflare as well?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Clear cache via php code’ is closed to new replies.