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.
Installation
composer require soyuka/pmu
Add the service provider to config/app.php:
'providers' => [
// ...
Soyuka\Pmu\PmuServiceProvider::class,
],
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).
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
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).
Isolated Development
Use pmu:serve to spin up a local server for a specific package:
php artisan pmu:serve auth
http://localhost:8000/auth to packages/auth/public.Shared Dependencies
Define shared directories in config/pmu.php:
'shared' => [
'config' => base_path('shared/config'),
'resources' => base_path('shared/resources'),
],
pmu:share:link:
php artisan pmu:share:link
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');
}
}
Plugin Integration
Develop plugins for a specific package (e.g., auth):
packages/auth/plugins/ (e.g., packages/auth/plugins/Logging/).config/pmu.php:
'plugins' => [
'auth' => [
'Logging' => base_path('packages/auth/plugins/Logging'),
],
],
php artisan pmu:plugins:enable auth Logging
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::prefix('auth')->middleware(['web', 'pmu.auth'])->group(function () {
// Auth package routes
});
app/Http/Kernel.php:
protected $routeMiddleware = [
// ...
'pmu.plugin.logging' => \Soyuka\Pmu\Plugins\LoggingMiddleware::class,
];
Caching Quirks
config/pmu.php:
php artisan config:clear
composer dump-autoload after structural changes.php artisan pmu:plugins:clear
Path Resolution
pmu_path('auth') instead of hardcoding paths (e.g., base_path('packages/auth')).php artisan pmu:debug
config/pmu.php to avoid "Plugin not found" errors.Middleware Conflicts
pmu.auth) doesn’t override global middleware. Test with:
php artisan route:list | grep auth
pmu.plugin.<plugin-name>.Plugin Loading Order
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
],
],
],
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.
php artisan pmu:plugins:validate auth to check plugin configurations.Plugin Debugging: Enable plugin-specific debugging:
php artisan pmu:plugins:debug auth
Custom Commands
Extend Soyuka\Pmu\Console\PmuCommand for package-specific tasks (e.g., pmu:deploy:auth).
Soyuka\Pmu\Console\PluginCommand.Dynamic Configuration Override package configs at runtime:
pmu()->extend('auth', function ($config) {
$config['namespace'] = 'Auth\\Package';
return $config;
});
pmu()->plugin('auth')->extend('Logging', function ($config) {
$config['log_level'] = 'debug';
return $config;
});
Package Discovery Dynamically register packages via service providers:
public function register() {
pmu()->discover(base_path('packages/*/provider.php'));
}
pmu()->plugins()->discover(base_path('packages/*/plugins/*'));
Plugin Development Create reusable plugins for multiple packages:
vendor/soyuka/pmu/plugins/ (for shared use).php artisan pmu:plugins:publish
resources/views/vendor/pmu/plugins/.How can I help you explore Laravel packages today?