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

Pmu Laravel Package

soyuka/pmu

Monitor PHP-FPM status from Laravel. soyuka/pmu collects and exposes PHP-FPM pool metrics (requests, processes, slowlog-style stats) for easy health checks and observability in apps and dashboards.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require soyuka/pmu
    

    Add the service provider to config/app.php:

    'providers' => [
        // ...
        Soyuka\Pmu\PmuServiceProvider::class,
    ],
    
  2. Basic Configuration Publish the config file:

    php artisan vendor:publish --provider="Soyuka\Pmu\PmuServiceProvider" --tag="pmu-config"
    

    Update config/pmu.php with your monorepo structure (e.g., package paths, shared directories).

  3. First Use Case: Package Autoloading Define a package in config/pmu.php:

    'packages' => [
        'auth' => [
            'path' => base_path('packages/auth'),
            'autoload' => true,
        ],
    ],
    

    Run:

    php artisan pmu:autoload
    
  4. Enable Plugins for Sub-Projects To leverage the new plugin system for sub-projects:

    php artisan pmu:plugins:enable auth
    

    This allows extending functionality of individual packages via plugins (e.g., custom middleware, providers, or commands).


Implementation Patterns

Workflow: Package Development

  1. Isolated Development Use pmu:serve to spin up a local server for a specific package:

    php artisan pmu:serve auth
    
    • Maps http://localhost:8000/auth to packages/auth/public.
  2. Shared Dependencies Define shared directories in config/pmu.php:

    'shared' => [
        'config' => base_path('shared/config'),
        'resources' => base_path('shared/resources'),
    ],
    
    • Access shared files via pmu:share:link:
      php artisan pmu:share:link
      
  3. Task Automation Create custom tasks in app/Console/Commands/Pmu*:

    namespace App\Console\Commands;
    use Soyuka\Pmu\Console\PmuCommand;
    
    class BuildAuth extends PmuCommand {
        protected $signature = 'pmu:build:auth';
        protected $description = 'Build Auth package assets';
    
        public function handle() {
            $this->call('vendor:publish', ['--provider' => 'AuthServiceProvider']);
            $this->call('mix');
        }
    }
    
  4. Plugin Integration Develop plugins for a specific package (e.g., auth):

    • Place plugin files in packages/auth/plugins/ (e.g., packages/auth/plugins/Logging/).
    • Register plugins in config/pmu.php:
      'plugins' => [
          'auth' => [
              'Logging' => base_path('packages/auth/plugins/Logging'),
          ],
      ],
      
    • Enable plugins for a package:
      php artisan pmu:plugins:enable auth Logging
      

Integration Tips

  • Laravel Mix/Vite: Extend webpack.mix.js to support package-specific builds:
    const mix = require('laravel-mix');
    const pmu = require('soyuka/pmu/mix');
    
    pmu.packages(['auth', 'dashboard']).forEach(pkg => {
        mix.setPublicPath(`packages/${pkg}/public`);
        mix.js(`packages/${pkg}/resources/js/app.js`, `packages/${pkg}/public/js`);
    });
    
  • Route Isolation: Use middleware to scope routes:
    Route::prefix('auth')->middleware(['web', 'pmu.auth'])->group(function () {
        // Auth package routes
    });
    
  • Plugin Middleware: Register plugin-specific middleware in app/Http/Kernel.php:
    protected $routeMiddleware = [
        // ...
        'pmu.plugin.logging' => \Soyuka\Pmu\Plugins\LoggingMiddleware::class,
    ];
    

Gotchas and Tips

Pitfalls

  1. Caching Quirks

    • Clear cached configs after changing config/pmu.php:
      php artisan config:clear
      
    • Autoload caches may persist; run composer dump-autoload after structural changes.
    • Plugin Caching: After enabling/disabling plugins, clear the plugin cache:
      php artisan pmu:plugins:clear
      
  2. Path Resolution

    • Use pmu_path('auth') instead of hardcoding paths (e.g., base_path('packages/auth')).
    • Shared directories take precedence over package-specific ones; verify with:
      php artisan pmu:debug
      
    • Plugin Paths: Ensure plugin directories are correctly defined in config/pmu.php to avoid "Plugin not found" errors.
  3. Middleware Conflicts

    • Ensure package-specific middleware (e.g., pmu.auth) doesn’t override global middleware. Test with:
      php artisan route:list | grep auth
      
    • Plugin Middleware: Avoid naming conflicts with existing middleware by prefixing plugin middleware with pmu.plugin.<plugin-name>.
  4. Plugin Loading Order

    • Plugins are loaded in alphabetical order by default. Use the priority key in config/pmu.php to control loading order:
      'plugins' => [
          'auth' => [
              'Logging' => [
                  'path' => base_path('packages/auth/plugins/Logging'),
                  'priority' => 10, // Lower numbers load first
              ],
          ],
      ],
      

Debugging

  • Log Package Events: Enable debug mode in config/pmu.php:

    'debug' => env('PMU_DEBUG', false),
    

    Check logs at storage/logs/pmu.log.

  • Validate Structure: Run php artisan pmu:validate to ensure package directories conform to expectations.

    • Plugin Validation: Use php artisan pmu:plugins:validate auth to check plugin configurations.
  • Plugin Debugging: Enable plugin-specific debugging:

    php artisan pmu:plugins:debug auth
    

Extension Points

  1. Custom Commands Extend Soyuka\Pmu\Console\PmuCommand for package-specific tasks (e.g., pmu:deploy:auth).

    • Plugin Commands: Create plugin-specific commands by extending Soyuka\Pmu\Console\PluginCommand.
  2. Dynamic Configuration Override package configs at runtime:

    pmu()->extend('auth', function ($config) {
        $config['namespace'] = 'Auth\\Package';
        return $config;
    });
    
    • Plugin Configs: Extend plugin configurations dynamically:
      pmu()->plugin('auth')->extend('Logging', function ($config) {
          $config['log_level'] = 'debug';
          return $config;
      });
      
  3. Package Discovery Dynamically register packages via service providers:

    public function register() {
        pmu()->discover(base_path('packages/*/provider.php'));
    }
    
    • Plugin Discovery: Discover plugins dynamically:
      pmu()->plugins()->discover(base_path('packages/*/plugins/*'));
      
  4. Plugin Development Create reusable plugins for multiple packages:

    • Place plugin skeletons in vendor/soyuka/pmu/plugins/ (for shared use).
    • Publish plugin templates:
      php artisan pmu:plugins:publish
      
    • Customize plugin templates in resources/views/vendor/pmu/plugins/.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor