spatie/global-ray
Install Ray globally to use ray(), rd(), dump() and dd() in any PHP project. Send debug output (arrays, HTML, queries, markdown) to the Ray desktop app, measure performance, and pause execution—same debugging workflow across frameworks and plain PHP.
Installation:
composer global require spatie/global-ray
Ensure ~/.composer/vendor/bin is in your PATH or use the full path to global-ray in commands.
First Use:
Add this to any PHP file (e.g., app/Commands/TestCommand.php):
ray('Hello from a non-Laravel file!');
Launch Ray via ray CLI command, then run your PHP script. Output appears in the Ray UI.
Laravel Integration: For Laravel projects, install the Laravel Ray package alongside:
composer require spatie/laravel-ray
Publish config (optional):
php artisan vendor:publish --provider="Spatie\LaravelRay\RayServiceProvider"
Debugging Non-Laravel PHP:
Use ray() in CLI scripts, cron jobs, or standalone PHP files. Example:
// In a cron job (e.g., app/Jobs/ProcessData.php)
ray(['user_ids' => [1, 2, 3], 'status' => 'pending']);
Laravel-Specific Patterns:
public function boot()
{
ray('Service provider booting...');
}
ray('User created:', $user->toArray());
ray('Command executed with args:', $args);
Performance Profiling:
Use ray()->startTimer() in long-running scripts:
$timer = ray()->startTimer('data_processing');
// ... process data ...
ray()->stopTimer($timer);
Conditional Debugging:
Wrap ray() in environment checks:
if (app()->environment('local')) {
ray('Debug info:', $variable);
}
if (!app()->runningUnitTests()) {
ray('Test debug info');
}
ray('Job payload:', $this->payload);
ray
php artisan tinker
Global vs. Project-Specific:
spatie/global-ray is global (installed via Composer global). Ensure it’s in your PATH or use the full path:
~/.composer/vendor/bin/global-ray
spatie/laravel-ray.Ray Not Launching:
ray binary is executable and no port conflicts (default: 8080).ray --debug
Performance Overhead:
ray() in tight loops or production. Use:
if (app()->environment('local')) {
ray('Heavy debug data');
}
Output Truncation:
ray()->setMaxOutputSize(0) to disable limits.Ray Not Receiving Data:
ray in terminal).ray('test') in a standalone script.Laravel-Specific Issues:
$this->app->singleton('ray', function () {
return new \Spatie\Ray\Ray();
});
Custom Ray Channels:
Use ray()->channel('custom') to categorize logs:
ray('API request')->channel('api');
Ray Middleware: Create a middleware to auto-log requests:
public function handle($request, Closure $next)
{
ray('Incoming request:', $request->all());
return $next($request);
}
Ray in Exceptions:
Log exceptions globally in App\Exceptions\Handler:
public function report(Throwable $exception)
{
ray('Unhandled exception:', $exception);
}
Ray with MCP (Multi-Channel Protocol): For AI/third-party integrations, use the MCP server:
ray('AI response')->mcp();
~/.config/ray/config.json for global settings (e.g., themes, output size).php artisan vendor:publish --tag=laravel-ray-config
Key options:
'enabled' => env('RAY_ENABLED', false),
'max_output_size' => 1024, // in KB
'channels' => ['default', 'api', 'cli'],
How can I help you explore Laravel packages today?