Laravel Package for OPcache

Overview

Laravel OPcache

Latest Version on Packagist Software License Total Downloads

This package contains some useful Artisan commands to work with PHP OPcache.

If you want to learn more about OPcache and what it can do for your Laravel application, read the article on Medium.

Requirements

This package requires Laravel 7 or newer.

Installation

You can install the package via Composer:

composer require appstract/laravel-opcache

If you need to change config values, you can publish the config file with:

php artisan vendor:publish --provider="Appstract\Opcache\OpcacheServiceProvider" --tag="config"

Make sure your APP_URL is set correctly in .env.

If you want to set a different url to call the OPcache routes (for use with a load balancer for example), you can set OPCACHE_URL.

Usage

Clear OPcache:

php artisan opcache:clear

Show OPcache config:

php artisan opcache:config

Show OPcache status:

php artisan opcache:status

Pre-compile your application code:

php artisan opcache:compile {--force}

Note: opcache.dups_fix must be enabled, or use the --force flag. If you run into "Cannot redeclare class" errors, enable opcache.dups_fix or add the class path to the exclude list.

Programmatic usage:

use Appstract\Opcache\OpcacheFacade as OPcache;

...

OPcache::clear();

Contributing

Contributions are welcome, thanks to y'all :)

About Appstract

Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment.

License

The MIT License (MIT). Please see License File for more information.

Comments
  • [Appstract\LushHttp\Exception\LushRequestException] The requested URL returned error: 500 Internal Server Error

    [Appstract\LushHttp\Exception\LushRequestException] The requested URL returned error: 500 Internal Server Error

    Hi, I'm working with my staging environment, Laravel 5.1

    On running, php artisan opcache:status or php artisan opcache:clear I get following, [Appstract\LushHttp\Exception\LushRequestException] The requested URL returned error: 500 Internal Server Error

    Here are my Log

    Access log

    "GET /opcache-api/status? HTTP/1.0" 500 5669 "App-URL/opcache-api/status?" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Lush Http Client"

    Error log Got error 'PHP message: PHP Fatal error: Class 'Illuminate\Auth\Access\AuthorizationException' not found in /path-to-vendor/appstract/laravel-opcache/src/Http/Middleware/Request.php on line 29\n', referer: App-URL/opcache-api/status?

    Laravel.log staging.ERROR: exception 'Appstract\LushHttp\Exception\LushRequestException' with message 'The requested URL returned error: 500 Internal Server Error' in /path-to-vendor/appstract/lush-http/src/Request/CurlRequest.php:119

    I've seen the issue https://github.com/appstract/laravel-opcache/issues/12 , but that seems to be different problem.

    Kindly can you help me get through this issue !

    I suspect that's because opcache can't locate framework/src/Illuminate/Auth/Access/AuthorizationException.php in 5.1 , does this package supports 5.1 ?

    Here are my opcache settings: Zend OPcache

    Opcode Caching => Up and Running Optimization => Enabled Startup => OK Shared memory model => mmap Cache hits => 0 Cache misses => 0 Used memory => 5465056 Free memory => 61643808 Wasted memory => 0 Interned Strings Used memory => 623112 Interned Strings Free memory => 3571192 Cached scripts => 0 Cached keys => 0 Max keys => 3907 OOM restarts => 0 Hash keys restarts => 0 Manual restarts => 0

    Directive => Local Value => Master Value opcache.blacklist_filename => no value => no value opcache.consistency_checks => 0 => 0 opcache.dups_fix => Off => Off opcache.enable => On => On opcache.enable_cli => On => On opcache.enable_file_override => Off => Off opcache.error_log => no value => no value opcache.fast_shutdown => 0 => 0 opcache.file_update_protection => 2 => 2 opcache.force_restart_timeout => 180 => 180 opcache.inherited_hack => On => On opcache.interned_strings_buffer => 4 => 4 opcache.load_comments => 1 => 1 opcache.lockfile_path => /tmp => /tmp opcache.log_verbosity_level => 1 => 1 opcache.max_accelerated_files => 2000 => 2000 opcache.max_file_size => 0 => 0 opcache.max_wasted_percentage => 5 => 5 opcache.memory_consumption => 64 => 64 opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF opcache.preferred_memory_model => no value => no value opcache.protect_memory => 0 => 0 opcache.restrict_api => no value => no value opcache.revalidate_freq => 2 => 2 opcache.revalidate_path => Off => Off opcache.save_comments => 1 => 1 opcache.use_cwd => On => On opcache.validate_permission => Off => Off opcache.validate_root => Off => Off opcache.validate_timestamps => On => On

    bug 
    opened by umairiftikhar-ca 20
  • php artisan opcache:compile exception

    php artisan opcache:compile exception

    Running php artisan opcache:compile I receive: `ParseError: syntax error, unexpected '|', expecting variable (T_VARIABLE) (truncated...)

    at vendor/laravel/framework/src/Illuminate/Http/Client/Response.php:241 237▕ { 238▕ $callback = func_get_args()[0] ?? null; 239▕ 240▕ if ($this->failed()) { ➜ 241▕ throw tap(new RequestException($this), function ($exception) use ($callback) { 242▕ if ($callback && is_callable($callback)) { 243▕ $callback($this, $exception); 244▕ } 245▕ }); `

    Laravel 8.22.1 PHP 7.4.14

    opened by php-writerman 14
  • The requested URL returned error: 404 Not Found

    The requested URL returned error: 404 Not Found

    Whenever I execute php artisan opcache:clear it returns me this error:

    php artisan opcache:config
    
    
      [Appstract\LushHttp\Exception\LushRequestException]
      The requested URL returned error: 404 Not Found
    

    Am I doing something wrong?

    opened by Cannonb4ll 14
  • curl_setopt_array(): CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled

    curl_setopt_array(): CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled

    I have the following problem when trying to run command php artisan opcahce:clear in laravel 5.5. Please help me to solve this problem.

    In Curl.php line 32:

    curl_setopt_array(): CURLOPT_DNS_USE_GLOBAL_CACHE cannot be activated when thread safety is enabled

    opened by pagnax 12
  • Need ability to ignore SSL errors in artisan commands

    Need ability to ignore SSL errors in artisan commands

    php artisan opcache:clear
    Unable to communicate securely with peer: requested domain name does not match the server's certificate.
    Url: https://localhost/opcache-api/clear?key=...
    
    curl -v --insecure https://localhost/opcache-api/clear?key=...
    {"result":true}
    
    opened by maksimru 11
  •  There are no commands defined in the

    There are no commands defined in the "opcache" namespace.

    I have been install with running composer require appstract/laravel-opcache and setup

    // config/app.php
    'providers' => [
        ...
        Appstract\Opcache\OpcacheServiceProvider::class,
    ];
    

    and then composer dump-autoload but I still get error like this

      There are no commands defined in the "opcache" namespace.       
      Did you mean this?                                              
          cache
    

    please help me

    I'm use laravel 5.4

    opened by tommoholmes 11
  • Package not usable after a Load balancer and with more instances

    Package not usable after a Load balancer and with more instances

    We wanted to use this package in our deploy scripts to flush the cache but because of the APP_URL usage in the code only one "random" instance will be selected and flushed if we set the APP_URL to something different then localhost (the default). Is it a possibility to use a different paramater or always use localhost (hardcoded) instead of using APP_URL. That way, a possible loadbalancer will never matter, but only the instance itself is available.

    opened by glamorous 9
  • Cannot redeclare Composer\Autoload\includeFile() (previously declared in /code/vendor/composer/ClassLoader.php:442)

    Cannot redeclare Composer\Autoload\includeFile() (previously declared in /code/vendor/composer/ClassLoader.php:442)

    Possibly related to #75.

    opcache.dups_fix seems to be able to solve this problem, but it doesn't work as expected...

    image image

    We don't see any errors in the terminal, but we confirmed Sentry error report has been actually sent.

    opened by mpyw 8
  • says

    says "nothing to clear" and requires a php-restart to clear

    I've been using this for months and it was working fine.. but today I had to install a new composer package. I deployed my new composer.json/.lock and ran composer install --no-dev on production

    then I started having this Uncaught ReflectionException: Class view does not exist error.. it took me a while to figure out the pa opcache:clear command was failing

    I tried running it and it always said "Opcode cache: Nothing to clear" .. what ?? =/

    I checked the options for that command and don't see a --force.. maybe there should be a --force command? I'd feel safer with it.. not sure why this happened but it caused some downtime and made me panic a bit

    Finally I did a sudo service php7.2-fpm restart and that cleared the error.. clearly it wasn't seeing the new composer changes

    opened by vesper8 8
  • cmnds error

    cmnds error

    first many thanx for this package & for the article as well.

    atm am getting error on each run of opcache:config, sometimes it could be

     [ErrorException]
      Trying to get property of non-object
    

    or

     [GuzzleHttp\Exception\RequestException]
      cURL error 56: Recv failure: Connection reset by peer (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
    
    opened by ctf0 7
  • OPcache not configured error message

    OPcache not configured error message

    Hi, I am using fresh php:7.3-apache docker.

    I have got 2 error message in laravel log when I run php artisan opcache:compile:

    Cannot declare class FilesystemRegexFilter, because the name is already in use
    Cannot use Riak\Object as Object because 'Object' is a special class name
    

    It compile about 5000 file then I get error message in promt: "OPcache not configured"

    Here is my opcache.ini custom file:

    opcache.enable=1
    opcache.memory_consumption=512
    opcache.interned_strings_buffer=64
    opcache.max_accelerated_files=32531
    opcache.validate_timestamps=0
    opcache.save_comments=1
    opcache.fast_shutdown=1
    opcache.dups_fix=1
    
    Configuration info:
    +---------------------------------------+------------+
    | opcache.enable                        | true       |
    | opcache.enable_cli                    | false      |
    | opcache.use_cwd                       | true       |
    | opcache.validate_timestamps           | false      |
    | opcache.validate_permission           | false      |
    | opcache.validate_root                 | false      |
    | opcache.inherited_hack                | true       |
    | opcache.dups_fix                      | true       |
    | opcache.revalidate_path               | false      |
    | opcache.log_verbosity_level           | 1          |
    | opcache.memory_consumption            | 512.00 MB  |
    | opcache.interned_strings_buffer       | 64         |
    | opcache.max_accelerated_files         | 32531      |
    | opcache.max_wasted_percentage         | 0.05       |
    | opcache.consistency_checks            | 0          |
    | opcache.force_restart_timeout         | 180        |
    | opcache.revalidate_freq               | 2          |
    | opcache.preferred_memory_model        |            |
    | opcache.blacklist_filename            |            |
    | opcache.max_file_size                 | 0          |
    | opcache.error_log                     |            |
    | opcache.protect_memory                | false      |
    | opcache.save_comments                 | true       |
    | opcache.enable_file_override          | false      |
    | opcache.optimization_level            | 2147467263 |
    | opcache.lockfile_path                 | /tmp       |
    | opcache.file_cache                    |            |
    | opcache.file_cache_only               | false      |
    | opcache.file_cache_consistency_checks | true       |
    | opcache.file_update_protection        | 2          |
    | opcache.opt_debug_level               | 0          |
    | opcache.restrict_api                  |            |
    | opcache.huge_code_pages               | false      |
    +---------------------------------------+------------+
    

    This problem should be solve by this config opcache.dups_fix=1 but it does not work well. Then I tried it with php:7.2-apache, the result is same.

    Do you have any ide what is wrong in my enviroment? If you have any question please let me know. Thanks.

    opened by pepeshark 6
  • Opcache issue

    Opcache issue

    I got two laravel projects running on the same apache2 server on my local system, Now when I run enlightn package on both projects then one of them shows the "OPcache is not enabled" error while another works completely fine

    when i check phpinfo(); it also shows OPcache up and running for both project. also tried uncommenting OPcache config in php.ini files in apache2

    I also tried running this "PHP -i | grep opcache" command it also shows everything is okay

    opened by jalpab 0
  • Can't run opcache:compile

    Can't run opcache:compile

    To reproduce:

    $ php artisan opcache:clear
    OPcache cleared
    
    $ php artisan opcache:compile --force
    Compiling scripts...
    Illuminate\Http\Client\RequestException
    HTTP request returned status code 500
    at vendor/laravel/framework/src/Illuminate/Http/Client/Response.php:302
    298▕      */
    299▕     public function toException()
    300▕     {
    301▕         if ($this->failed()) {
    ➜ 302▕             return new RequestException($this);
    303▕         }
    304▕     }
    305▕
    306▕     /**
    +15 vendor frames 
    16  artisan:37
    Illuminate\Foundation\Console\Kernel::handle()
    

    PHP: 8.1.2 Laravel: 9.36.4 laravel-opcache: 4.0.2

    opened by LocalHeroPro 0
  • php artisan opcache:clear exception

    php artisan opcache:clear exception

    Running php artisan opcache:clear i receive: ` Illuminate\Http\Client\RequestException

    HTTP request returned status code 500: ... Illuminate\Contracts\Container\BindingResolutionException: Target class [Appstract\Opcache\Http\Controllers\OpcacheController] does not exist. in file /home/infinite/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 879 ` Tryed with :status and :compile with the same error.

    Followed what some user suggested in #123 to get the full error, in order to detect if some other package was causing this error and exclude it. But it seems like it does not find its own OpcacheController?

    Laravel v9.17.0 PHP 8.1.7

    opened by AComasSamcla 0
  • opcache:clear not working

    opcache:clear not working

    This package was working fine when I installed initially but now I am facing very strange issue just to clear opcache using the following command. php artisan opcache:clear

    My concern is my Laravel application executes previous version code even after clearing the opacache several times. I believe It must have to execute latest source code. I tried after php-fpm reload. I also restarted my Apache Fast CGI server. I even tried after executing the following Artisan commands but it still executes previous version code for me.

    php artisan config:cache
    php artisan route:cache
    php artisan view:cache
    php artisan clear-compiled
    php artisan optimize
    
    

    Here are my application environments if anybody can help me to figure out the issue.

    PHP Version: 7.4.21
    Laravel Version: 8.42.1
    laravel-opcache package version: 4.0.2
    

    Opcache Status:

    opcache-status-screenshot

    Opcache Configuration:

    opcache-config-screenshot

    I am not sure what I am missing. Please help me to fix it. Any kind of help will be appreciate.

    Thanks

    opened by jiteshtandel 0
  • Trying to access array offset on value of type null

    Trying to access array offset on value of type null

    I come across this error such as below

    php : v8.0.3 with opcache and xdebug laravel : v8 LTS

    note: eror occure while pre-compile commanding

    sorry for bad english

    Trying to access array offset on value of type null
    
      at C:\xampp_old\htdocs\nib-backend-v2\vendor\laravel\framework\src\Illuminate\Http\Client\Response.php:349
        345▕      */
        346▕     #[\ReturnTypeWillChange]
        347▕     public function offsetGet($offset)
        348▕     {
      ➜ 349▕         return $this->json()[$offset];
        350▕     }
        351▕
        352▕     /**
        353▕      * Set the value at the given offset.
    
      1   C:\xampp_old\htdocs\nib-backend-v2\vendor\laravel\framework\src\Illuminate\Http\Client\Response.php:349
          Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Trying to access array offset on value of type null", "C:\xampp_old\htdocs\nib-backend-v2\vendor\laravel\framework\src\Illuminate\Http\Client\Response.php")
    
      2   C:\xampp_old\htdocs\nib-backend-v2\vendor\appstract\laravel-opcache\src\Commands\Compile.php:40
          Illuminate\Http\Client\Response::offsetGet("result")
    
    opened by theara72 4
  • Not compatible with php artisan optimize

    Not compatible with php artisan optimize

    Hi,

    I noticed the lib doesn't work if you're compiling with php artisan optimize.

    As a workaround i'm doing

    php artisan optimize clear
    php artisan opcache:clear
    php artisan optimize
    

    You might need to declare a route somewhere in your package.

    opened by Kryptonien 1
Releases(4.0.2)
Owner
Appstract
We build packages and tools for PHP, Laravel & JavaScript.
Appstract
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.

Chat Create a Chat application for your multiple Models Table of Contents Click to expand Introduction Installation Usage Adding the ability to partic

Tinashe Musonza 931 Dec 24, 2022
This package provides extended support for our spatie/enum package in Laravel.

Laravel support for spatie/enum This package provides extended support for our spatie/enum package in Laravel. Installation You can install the packag

Spatie 264 Dec 23, 2022
Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package

Laravel Testing Helper for Packages Development Testbench Component is the de-facto package that has been designed to help you write tests for your La

Orchestra Platform 1.9k Dec 29, 2022
🥳🔐 This package is a Laravel package that checks if an email address is a spammer

This package is a Laravel package that checks if an email address is a spammer. It verifies your signups and form submissions to confirm that they are legitimate.

Endurance, the Martian 15 Dec 19, 2022
GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn

GeoLocation in PHP (API) ?? ?? ?? This package helps you to know a lot of information about the current user by his ip address ?? ?? ?? This package h

Abdullah Karam 4 Dec 8, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022
A Laravel package that adds a simple image functionality to any Laravel model

Laraimage A Laravel package that adds a simple image functionality to any Laravel model Introduction Laraimage served four use cases when using images

Hussein Feras 52 Jul 17, 2022
laravel-vat is a package that contains the Laravel related wiring code for ibericode/vat

laravel-vat is a package that contains the Laravel related wiring code for ibericode/vat, helping you deal with VAT legislation for businesses based in the EU.

Danny van Kooten 117 Dec 5, 2022
Laravel Backup Panel provides a dashboard for spatie/laravel-backup package.

Laravel Backup Panel Laravel Backup Panel provides a dashboard for spatie/laravel-backup package. It lets you: create a backup (full | only database |

Pavel Mironchik 366 Dec 6, 2022
Laravel package to find performance bottlenecks in your laravel application.

Laravel Meter Laravel Meter monitors application performance for different things such as requests, commands, queries, events, etc and presents result

Sarfraz Ahmed 230 Dec 27, 2022
Laravel 2-Step Verification is a package to add 2-Step user authentication to any Laravel project easily.

Laravel 2-Step verification is a package to add 2-Step user authentication to any Laravel project easily. It is configurable and customizable. It uses notifications to send the user an email with a 4-digit verification code. Laravel 2-Step Authentication Verification for Laravel. Can be used in out the box with Laravel's authentication scaffolding or integrated into other projects.

Jeremy Kenedy 204 Dec 23, 2022
This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.

Laravel FFMpeg This package provides an integration with FFmpeg for Laravel 6.0 and higher. Laravel's Filesystem handles the storage of the files. Lau

Protone Media 1.3k Jan 1, 2023
Laravel Users | A Laravel Users CRUD Management Package

A Users Management Package that includes all necessary routes, views, models, and controllers for a user management dashboard and associated pages for managing Laravels built in user scaffolding. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0 and 8.0.

Jeremy Kenedy 393 Nov 28, 2022
Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Rahul Thapa 2 Oct 16, 2022
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.

Webdevetc BlogEtc - Complete Laravel Blog Package Quickly add a blog with admin panel to your existing Laravel project. It has everything included (ro

WebDevEtc. 227 Dec 25, 2022
Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel 5.

Laravel-Mediable Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel. Features Filesystem-driven appro

Plank Design 654 Dec 30, 2022