PHP code example of jobviz / agent

1. Go to this page and download the library: Download jobviz/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/ */

    

jobviz / agent example snippets


use Jobviz\Agent\Config;
use Jobviz\Agent\Jobviz;
use Jobviz\Agent\Providers\SymfonyMessengerProvider;

Jobviz::init(new Config(
    apiKey: $_ENV['JOBVIZ_API_KEY'],
    provider: new SymfonyMessengerProvider(
        dispatcher: $container->get('event_dispatcher'),
    ),
));

use Jobviz\Agent\Config;
use Jobviz\Agent\Jobviz;
use Jobviz\Agent\Providers\MultiProvider;
use Jobviz\Agent\Providers\LaravelQueueProvider;
use Jobviz\Agent\Providers\SymfonyMessengerProvider;

Jobviz::init(new Config(
    apiKey: $_ENV['JOBVIZ_API_KEY'],
    provider: new MultiProvider([
        new LaravelQueueProvider($app['events']),
        new SymfonyMessengerProvider($dispatcher),
    ]),
));

use Jobviz\Agent\Jobviz;

// Inside your job's handle() method
Jobviz::log(
    ['id' => $this->job->getJobId(), 'name' => 'SendEmail', 'queue' => 'emails'],
    'Fetching template',
);

Jobviz::log(
    ['id' => $this->job->getJobId(), 'name' => 'SendEmail', 'queue' => 'emails'],
    'Sending email',
    ['recipients' => count($this->recipients)],
);

use Jobviz\Agent\Jobviz;

Jobviz::trackDeployment(
    version: '1.4.2',
    commitHash: 'abc123f',
    description: 'Fix email retry logic',
);

use Jobviz\Agent\Config;

// 1. Disable input capture entirely
new Config(apiKey: $key, provider: $provider, captureInput: false);

// 2. Disable stack trace capture
new Config(apiKey: $key, provider: $provider, captureStackTraces: false);

// 3. Redact built-in sensitive keys (password, secret, token, etc.)
new Config(apiKey: $key, provider: $provider, redactKeys: true);

// 4. Redact custom keys (merged with built-in set)
new Config(apiKey: $key, provider: $provider, redactKeys: ['ssn', 'dob', 'bankAccount']);

// 5. Disable redaction entirely
new Config(apiKey: $key, provider: $provider, redactKeys: false);

use Jobviz\Agent\Config;
use Jobviz\Agent\JobvizAgent;

$agent = new JobvizAgent(new Config(
    apiKey: $_ENV['JOBVIZ_API_KEY'],
    provider: $provider,
));

$agent->start();

// Later...
$agent->stop();

use Closure;
use Jobviz\Agent\JobEvent;
use Jobviz\Agent\Providers\QueueProviderInterface;

class MyQueueProvider implements QueueProviderInterface
{
    public function connect(Closure $push): void
    {
        // Subscribe to your queue system and call $push(new JobEvent(...)) for each event
    }

    public function disconnect(): void
    {
        // Clean up connections
    }
}

use Jobviz\Agent\Jobviz;

register_shutdown_function(fn() => Jobviz::stop());
bash
php artisan vendor:publish --provider="Jobviz\Agent\Laravel\JobvizServiceProvider"