Coder Social home page Coder Social logo

opcachebundle's Introduction

Provide a command line to clear opcache cache from the console.

The problem with opcache is that it's impossible to clear it from command line. Because even if you enable opcache for PHP CLI, it's a different instance than, say, your Apache PHP or PHP-CGI opcache instance.

The trick here is to create a file in the web dir, execute it through HTTP, then remove it.

Installation

  1. Add it to your composer.json:

    {
        "require": {
            "sixdays/opcache-bundle": "dev-master"
        }
    }

    or:

        composer require sixdays/opcache-bundle
        composer update sixdays/opcache-bundle
  2. Add this bundle to your application kernel:

     // app/AppKernel.php
     public function registerBundles()
     {
         return array(
             // ...
             new Sixdays\OpcacheBundle\SixdaysOpcacheBundle(),
             // ...
         );
     }
    
  3. Configure sixdays_opcache service:

     # app/config/config.yml
     sixdays_opcache:
         base_url:   http://localhost/ #could also be https://, or http://127.0.0.1:8000/, or any other valid URL
         web_dir:    %kernel.root_dir%/../web
    

Usage

Clear all opcache cache:

      $ php app/console opcache:clear

Capifony usage

To automatically clear opcache cache after each capifony deploy you can define a custom task

namespace :symfony do
  desc "Clear opcache cache"
  task :clear_opcache do
    capifony_pretty_print "--> Clear opcache cache"
    run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} opcache:clear --env=#{symfony_env_prod}'"
    capifony_puts_ok
  end
end

and add this hook

# opcache
after "deploy", "symfony:clear_opcache"

Nginx configuration

If you are using nginx and limiting PHP scripts that you are passing to fpm you need to allow 'opcache' prefixed php files. Otherwise your web server will return the requested PHP file as text and the system won't be able to clear the opcache cache.

Example configuration:

# Your virtual host
server {
  ...
  location ~ ^/(app|app_dev|opcache-.*)\.php(/|$) { { # This will allow opcache (opcache-{MD5HASH}.php) files to be processed by fpm
    fastcgi_pass                127.0.0.1:9000;
    ...

opcachebundle's People

Contributors

akondas avatar maks3w avatar ricbra avatar sixdayz avatar stollr 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  avatar  avatar  avatar

Watchers

 avatar

opcachebundle's Issues

Update packagist

Hi @sixdayz ,

Is the service hook installed for packagist for the repo?

If not, could you update manually on packagist so we can use composer with the latest updates from this repo? Thank you very much.

Error file not found

We are using Deployer to deploy our projects on the production servers. I have added the opcache:clear command as an additional task that is executed after the document root is symlinked with the project directory.

But it happens regularly (not always!) that such an error is thrown:

Curl error reading "https://www.my-domain.com/opcache-e95b639196d2836834a
449638ddcac2a.php": The requested URL returned error: 404 Not Found

Any idea what the reason could be?

It would be nice if the realpath of the created file could be logged in case of an exception. That would help debugging the issue.

Tag it ?

  • The requested package sixdays/opcache-bundle master is satisfiable by sixdays/opcache-bundle[dev-master] but these conflict with your requirements or minimum-stability.

Can u add first tag ?

using Guzzle

It would be nice using Guzzle instead of raw curl class (SRP).
Moreover, this package has no requirements about curl.

Check if opcache is installed

Hi.
Before calling opcache_reset() in the template, it would make sense to check if opcache is loaded.

if (!extension_loaded('opcache')) {
    $success = false;
    $message = ' Opcode cache extension not loaded';
} else if (opcache_reset()) {
//... and the rest

command not working

I been testing this command (which is great BTW, thanks!), and it seems that, at least on my box, CURLing to an IP using the Host header doesn't make Nginx realize what virtualhost you are trying to access.

I think the easiest fix for this (which can also add a lot of flexibility) is the following:

Remove the IP, hostname, and protocol settings, add a new base_url setting (where you can use both an IP or a hostname, using port or not, http/s, just like you do in a browser), and update the command to work with this.

I'm making a pull request with this fix, so if you like it you can merge it.

Thanks!

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.