Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Opcache Gui Laravel Package

aping/laravel-opcache-gui

Laravel Opcache GUI for Laravel apps. Adds a simple web page to view PHP OPCache status and configuration. Install via Composer, register the service provider, and add a route to access the dashboard (e.g., /opcache). Flush support planned.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require aping/laravel-opcache-gui
    

    Publish the configuration file (if needed):

    php artisan vendor:publish --provider="Aping\LaravelOpcacheGui\OpcacheGuiServiceProvider" --tag="config"
    
  2. Configuration: Edit config/opcache-gui.php to set:

    • enabled (default: true)
    • route (default: /opcache-gui)
    • middleware (e.g., ['web'] or ['auth'] for restricted access)
    • cache_id (optional, if using multiple OPcache instances)
  3. First Use Case: Access the GUI via the configured route (e.g., /opcache-gui). No additional setup is required—it automatically integrates with Laravel’s OPcache configuration.


Implementation Patterns

Workflows

  1. Monitoring OPcache: Use the GUI to inspect:

    • Statistics: Hit rate, memory usage, cached scripts.
    • Script List: Filter by status (cached, expired, etc.).
    • Blacklist: Manage scripts excluded from caching.
  2. Debugging Performance Issues:

    • Check for scripts with low hit rates (potential candidates for optimization).
    • Identify memory leaks by monitoring OPcache memory growth over time.
  3. Integration with CI/CD:

    • Add a pre-deployment check (e.g., via a custom Artisan command) to validate OPcache settings:
      use Aping\LaravelOpcacheGui\Facades\OpcacheGui;
      
      public function checkOpcache()
      {
          $stats = OpcacheGui::stats();
          if ($stats['hit_rate'] < 0.75) {
              throw new \RuntimeException('OPcache hit rate too low!');
          }
      }
      
  4. Restricting Access:

    • Protect the route with middleware (e.g., auth) in the config:
      'middleware' => ['web', 'auth'],
      
    • Use environment-based toggling:
      'enabled' => env('APP_ENV') !== 'production',
      

Tips for Seamless Integration

  • Laravel Mix/Vite: Ensure OPcache is enabled in your local/dev environment to simulate production behavior.
  • Shared Hosting: If OPcache is managed by the host, verify the GUI reflects their configuration (not your local settings).
  • Custom Views: Extend the default Blade template by publishing the view:
    php artisan vendor:publish --provider="Aping\LaravelOpcacheGui\OpcacheGuiServiceProvider" --tag="views"
    

Gotchas and Tips

Pitfalls

  1. OPcache Disabled:

    • The GUI will show no data if OPcache is disabled in php.ini (opcache.enable=0).
    • Fix: Enable OPcache and restart PHP (e.g., sudo service php-fpm restart).
  2. Permission Issues:

    • If using opcache.file_cache, ensure the directory (opcache.file_cache=/tmp) is writable by the PHP process.
    • Debug: Check opcache.error_log for file permission errors.
  3. Multiple PHP Versions:

    • The GUI defaults to the CLI PHP version. For SAPI-specific OPcache (e.g., FPM), use:
      'cache_id' => 'php-fpm',
      
      in the config.
  4. Laravel Caching Conflicts:

    • OPcache and Laravel’s cache (e.g., Redis) are unrelated. The GUI only shows OPcache stats.

Debugging

  • No Data Displayed:

    • Verify OPcache is loaded (php -m | grep opcache).
    • Check Laravel logs (storage/logs/laravel.log) for OPcache-related errors.
  • Slow GUI Response:

    • OPcache stats are fetched via opcache_get_status(). High traffic may cause delays.
    • Mitigation: Cache the stats in memory (e.g., using Laravel’s cache):
      $stats = Cache::remember('opcache_stats', now()->addMinutes(5), function () {
          return opcache_get_status();
      });
      

Extension Points

  1. Custom Metrics:

    • Extend the GUI by adding a custom tab. Override the resources/views/vendor/opcache-gui/index.blade.php view and include additional logic:
      @inject('opcache', 'Aping\LaravelOpcacheGui\Facades\OpcacheGui')
      <div class="custom-metrics">
          {{ $opcache->customMetric() }}
      </div>
      
  2. Artisan Commands:

    • Create a custom command to reset OPcache:
      use Aping\LaravelOpcacheGui\Facades\OpcacheGui;
      
      class ResetOpcacheCommand extends Command
      {
          public function handle()
          {
              OpcacheGui::reset();
              $this->info('OPcache reset successfully.');
          }
      }
      
  3. Event Listeners:

    • Listen for OPcache changes (e.g., after deployment):
      use Aping\LaravelOpcacheGui\Events\OpcacheUpdated;
      
      OpcacheUpdated::listen(function ($event) {
          Log::info('OPcache updated at ' . now());
      });
      

Configuration Quirks

  • opcache.revalidate_freq:

    • A low value (e.g., 2) forces frequent script revalidation, reducing cache efficiency.
    • Recommendation: Set to 180 (3 minutes) for most applications.
  • opcache.max_accelerated_files:

    • If set too low, the GUI may show "Script not cached" for many files.
    • Default: 10000 (adjust based on your app’s size).
  • Environment-Specific Settings:

    • Use environment variables in config/opcache-gui.php:
      'route' => env('OPACHE_GUI_ROUTE', '/opcache-gui'),
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui