PHP code example of larasignal / agent

1. Go to this page and download the library: Download larasignal/agent library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

larasignal / agent example snippets


use LaraSignal\Agent\Facades\LaraSignal;

// Measure execution time of a code block
$result = LaraSignal::measure('stripe-payment', function () {
    return Stripe::charges()->create([...]);
});

// Record custom domain events
LaraSignal::event('OrderCompleted', ['order_id' => 109, 'amount' => 2500]);

// Attach contextual metadata to all subsequent events in the request/job
LaraSignal::context(['tenant_id' => $tenant->id, 'plan' => 'pro']);
LaraSignal::tag('checkout', 'high-value');

// Scope temporary context
LaraSignal::withContext(['batch' => 4], function () {
    // Events inside here inherit batch = 4
});

LaraSignal::user($user);

$document = LaraSignal::storage('read', 's3', $path, fn () => Storage::disk('s3')->get($path), [
    'size_bytes' => Storage::disk('s3')->size($path),
]);

LaraSignal::runtime('Application runtime', ['uptime_seconds' => 3600]);
LaraSignal::heartbeat('scheduler', 60);
LaraSignal::broadcastMetric('pusher', connections: 125, messages: 4800, attributes: ['cluster' => 'ap1']);
bash
php artisan larasignal:install
bash
php artisan larasignal:install --key=ls_live_a1b2c3... --sample-rate=1.0 --record-queries=true --no-interaction
bash
php artisan larasignal:run --sleep=3