1. Go to this page and download the library: Download highfive/inngest-php 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/ */
highfive / inngest-php example snippets
use DateTimeImmutable;
use Highfive\Inngest\Client;
use Highfive\Inngest\Event\Event;
use Highfive\Inngest\Cancellation\CancellationRequest;
$client = Client::create(
eventKey: getenv('INNGEST_EVENT_KEY'),
signingKey: getenv('INNGEST_SIGNING_KEY'),
);
// 1. Send an event (triggers any function listening for "user.signup")
$result = $client->events()->send(new Event(
name: 'user.signup',
data: ['userId' => 'u_123'],
));
$eventId = $result->ids[0];
// 2. Inspect the resulting run(s)
$runs = $client->runs()->forEvent($eventId);
// 3. Or block until the run finishes
$runs = $client->runs()->waitForEvent($eventId, timeoutSeconds: 60);
// 4. Cancel runs in bulk
$client->cancellations()->bulk(new CancellationRequest(
appId: 'acme-app',
functionId: 'schedule-reminder',
startedAfter: new DateTimeImmutable('-1 hour'),
startedBefore: new DateTimeImmutable('now'),
if: "event.data.userId == 'u_123'",
));
use Highfive\Inngest\Event\DispatchableEvent;
use Highfive\Inngest\Event\Event;
final readonly class UserSignedUp implements DispatchableEvent
{
public function __construct(
public string $userId,
public string $email,
) {}
public function toInngestEvent(): Event
{
return new Event(
name: 'user.signup',
data: [
'userId' => $this->userId,
'email' => $this->email,
],
);
}
}
$client->events()->send(new UserSignedUp('u_123', '[email protected]'));
use Highfive\Inngest\Client;
use Highfive\Inngest\Event\Event;
use Inngest; // Facade
class CheckoutController
{
public function __invoke(Client $inngest)
{
$inngest->events()->send(new Event('order.placed', ['orderId' => 42]));
// or:
Inngest::events()->send(new Event('order.placed', ['orderId' => 42]));
}
}