Code Monkey home page Code Monkey logo

wiardvanrij / m2-opcache-manager Goto Github PK

View Code? Open in Web Editor NEW
27.0 5.0 6.0 30 KB

Magento2 - PHP Opcache | Allows the purge/clear/flush of the PHP OpCache via the CLI and Magento2 Backend

Home Page: https://www.sysrant.com

License: Open Software License 3.0

PHP 96.64% HTML 3.36%
php-opcache cli magento2-backend magento2 magento2-extension php php7 opcache magento magento2-module magento-extension magento-module magento-2-extension magento-2

m2-opcache-manager's Introduction

Magento2 OpCache Manager

Allows the purge/clear/flush of the PHP OpCache via the CLI and Magento2 Backend

Unmaintained

I still see a lot of activity on this repository (usage). I just wanted to note that I'm not maintaining this plugin anymore. This is because I'm not working with Magento at this point. Therefore I have no interest in making new changes/features. Though feel free to make pull-requests and I will process these.

Why

Because PHP OpCache is almost the de facto standard in current server/application setups. Most users/developers are usinga simple PHP script to clear the cache or simply ignore this cache. With this extension you can use it in your build/deployment process via the CLI. Also provided is an extension to the Magento2 backend. With a simple click you can purge the cache.

About me

I'm a DevOps engineer for a full service digital agency in the Netherlands. When possible I try to create opensource scripts / extentions and tools. If you appriciate my work, please be so kind to donate so I can keep drinking beer.

paypal

How the CLI works

It is simply not possible to clear the php OpCache via the CLI. I have created a workaround for that. Instead of actually running a static PHP file from the CLI, we do a curl request. Because it is a curl request, your webserver actually will parse this request via the "php cgi". This way we can clear it.

The issue we now have is that we do not want robots or "hackers" to be able to clear this cache. Therefor on execution we write a sort of "lock" file. Obviously removing it after clearing. This way "direct access" to this static page is not possible.

Additional cache management extended

Magento2 Additional cache management

OpCache purge

Magento2 OpCache purge

CLI Usage

php bin/magento opcache:status

Returns the opcache status:

bin/magento opcache:status
Array
(
    [opcache_enabled] => 1
    [cache_full] => 
    [restart_pending] => 
    [restart_in_progress] => 
    [memory_usage] => Array
        (
            [used_memory] => 78587744
            [free_memory] => 2068895904
            [wasted_memory] => 0
            [current_wasted_percentage] => 0
        )

    [interned_strings_usage] => Array
        (
            [buffer_size] => 20971520
            [used_memory] => 2283208
            [free_memory] => 18688312
            [number_of_strings] => 41723
        )

    [opcache_statistics] => Array
        (
            [num_cached_scripts] => 1289
            [num_cached_keys] => 1365
            [max_cached_keys] => 130987
            [hits] => 6
            [start_time] => 1510859030
            [last_restart_time] => 0
            [oom_restarts] => 0
            [hash_restarts] => 0
            [manual_restarts] => 0
            [misses] => 1289
            [blacklist_misses] => 0
            [blacklist_miss_ratio] => 0
            [opcache_hit_rate] => 0.46332046332046
        )

)
php bin/magento opcache:clear

Will clear the PHP OpCache

bin/magento opcache:clear
Cleared OpCache

Install with Composer

composer require webfixit/opcache

m2-opcache-manager's People

Contributors

osrecio avatar paulvandermeijs avatar wiardvanrij avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

m2-opcache-manager's Issues

Failed to get a result from the OpCache page

public_html]$ php bin/magento opcache:clear

Failed to get a result from the OpCache page

Status gives me:

Array
(
[opcache_enabled] => 1
[cache_full] =>
[restart_pending] =>
[restart_in_progress] =>
[memory_usage] => Array
(
[used_memory] => 49677320
[free_memory] => 84540408
[wasted_memory] => 0
[current_wasted_percentage] => 0
)

[interned_strings_usage] => Array
    (
        [buffer_size] => 8388608
        [used_memory] => 5481152
        [free_memory] => 2907456
        [number_of_strings] => 85174
    )

[opcache_statistics] => Array
    (
        [num_cached_scripts] => 2087
        [num_cached_keys] => 2087
        [max_cached_keys] => 7963
        [hits] => 10
        [start_time] => 1587597789
        [last_restart_time] => 0
        [oom_restarts] => 0
        [hash_restarts] => 0
        [manual_restarts] => 0
        [misses] => 2087
        [blacklist_misses] => 0
        [blacklist_miss_ratio] => 0
        [opcache_hit_rate] => 0.47687172150691
    )

)

etc. All seems fine.

What to do?

Change "allow flush" from file to something else - Making m2 readonly possible

Intro

When flushing the OpCache from the CLI we create a file called allow-opcache.flush. This file is for security measurements. After this file is created the frontend controller checks for this file. If the file exists it is allowed to actually flush the OpCache. This provides a safe and secure way that only authorized methods / clients are able to flush. If this check is not in place anyone could flush the OpCache.

Suggested change

I think we have a few options

  • On install create a secret key that is used when clearing the OpCache
  • Add a conf item in the database that is bool true/false if a flush is allowed
  • ???

Reason

There are users who prefer a "read only" environment. Writing/making files is not wanted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.