定制 sixdays/opcache-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sixdays/opcache-bundle

Composer 安装命令:

composer require sixdays/opcache-bundle

包简介

Provides a command line task to clear opcache cache from the console

README 文档

README

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;
    ...

统计信息

  • 总下载量: 61.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 30
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-09-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固