~/docs
Resonate
Resonate
1.x 1.8.1.4, current
Fledge Pulse
Toggle sidebar
Fledge Pulse
webpatser/fledge-pulse 1.8.1.4

Fledge Pulse 1.x

Examples

Register a custom storage driver, select a driver by environment, remember several card queries at once and clear the storage cache.

All examples are based on the package's README and source at v1.8.1.4.

Select a storage driver

Pick a driver in config/pulse.php or the environment:

PULSE_STORAGE_DRIVER=database

Register a storage driver

A package or your app registers its own driver with extend. The callback gets the container and returns a Laravel\Pulse\Contracts\Storage:

use Laravel\Pulse\Contracts\Storage;
use Laravel\Pulse\Fiber\Storage\StorageManager;
 
public function boot(): void
{
$this->app->make(StorageManager::class)->extend('clickhouse', function ($app): Storage {
return new ClickHouseStorage($app['config']->get('pulse.storage.clickhouse'));
});
}

Then set PULSE_STORAGE_DRIVER=clickhouse. Implement every method on the Storage contract (store, trim, purge, values, graph, aggregate, aggregateTypes, aggregateTotal) and return the same shapes as DatabaseStorage; the cards depend on them.

Note: Avoid static closures in extend, because Manager rebinds the callback to itself.

ClickHouseStorage is a placeholder for your own class.

Remember several queries concurrently

In a Livewire card, use RemembersConcurrently to run the cache misses of several queries at once:

use Laravel\Pulse\Facades\Pulse;
use Laravel\Pulse\Fiber\Livewire\Concerns\RemembersConcurrently;
use Laravel\Pulse\Livewire\Card;
 
class MyCard extends Card
{
use RemembersConcurrently;
 
public function render()
{
$results = $this->rememberMany([
'all' => fn ($interval) => Pulse::aggregate('cache_hit', ['count'], $interval),
'keys' => fn ($interval) => Pulse::aggregate('cache_hit', ['count'], $interval, limit: 25),
]);
 
[$all, $allTime, $allRunAt] = $results['all'];
 
// ...
}
}

Cache hits are returned as is; only the misses run, concurrently, through FiberDB::concurrent. On a shared PDO the storage lock serializes them, so this is safe but no faster than calling remember() in a row.

Reload the storage driver after a config change

On Octane and other long-lived workers, the driver instance is cached. After changing pulse.storage.* at runtime, drop the cached drivers:

use Laravel\Pulse\Fiber\Storage\StorageManager;
 
app(StorageManager::class)->forgetDrivers();

Keep a child fiber from recording

The ignore() depth is per fiber and is not inherited by fibers started with Fledge\Async\async(). Wrap the child closure in ignore() as well if it must not record:

use Laravel\Pulse\Facades\Pulse;
 
Pulse::ignore(function () {
// Work in this fiber is not recorded.
});