Cancellation
PHP has no language-level cancellation primitive equivalent to Node’s AbortSignal or Go’s context.Context. The SDK gives you two related controls instead: per-request timeouts and the underlying HTTP client’s own cancellation surface (if any).
Per-request timeouts
Section titled “Per-request timeouts”Every render and document method accepts a per-call timeout in seconds. It bounds each attempt, and the SDK applies it per request with Guzzle and Symfony HTTP Client; with another PSR-18 client, set the timeout on the client you inject:
use PoliPage\RenderInput;
$pdf = $client->render->pdf(new RenderInput( project: 'billing', template: 'invoice', data: ['invoiceNumber' => 'INV-001'], timeout: 5.0,));When the deadline trips on an API call, the SDK raises a PoliPage\Exception\TimeoutException (which extends ConnectionException) with the message Request timed out after <ms>ms. Timeouts are retried up to maxRetries times.
The same timeout bounds the presigned-URL download: the whole download for render->pdf() and downloadPdf(), and, for render->pdfStream(), the wait for the first byte and each gap between two chunks (an idle timeout, so a large PDF read at your pace is not cut off). The download is never retried, and a timeout there raises DOWNLOAD_FAILED with the message Failed to download PDF: timeout and no status.
HTTP-client cancellation
Section titled “HTTP-client cancellation”If you inject a Guzzle client and orchestrate your own promise-based pipeline, Guzzle’s request_options give you the underlying control:
use GuzzleHttp\Client as GuzzleClient;
$http = new GuzzleClient([ 'timeout' => 5.0, 'connect_timeout' => 2.0,]);
$client = new PoliPage( apiKey: $_ENV['POLI_PAGE_API_KEY'], httpClient: $http,);The SDK does not expose a public hook to abort an in-flight call from another thread or signal handler. If you need that, do it at the HTTP layer.
Example
Section titled “Example”<?php
require __DIR__ . '/vendor/autoload.php';
use PoliPage\Exception\TimeoutException;use PoliPage\PoliPage;use PoliPage\RenderInput;
$client = PoliPage::client($_ENV['POLI_PAGE_API_KEY']);
try { $pdf = $client->render->pdf(new RenderInput( project: 'billing', template: 'invoice', data: ['invoiceNumber' => 'INV-001'], timeout: 10.0, ));} catch (TimeoutException $e) { error_log('render timed out: ' . $e->getMessage()); throw $e;}