PHP · cURL

Use Backfire from PHP

PHP applications usually reach for cURL or Guzzle. Both work unchanged — point them at the relay and the outbound call is validated, logged and metered.

Notes for this client

  • cURL with CURLOPT_POSTFIELDS as a JSON string is the shortest form.
  • Keep the key in an environment variable or your secrets manager, not in a committed config file.
  • Set CURLOPT_TIMEOUT as well, so a slow relay cannot hang a PHP-FPM worker.
  • json_decode the envelope with associative arrays for simpler branching.

Working example

php
$payload = json_encode([
    'url' => 'https://api.github.com/zen',
    'method' => 'GET',
    'timeout_ms' => 8000,
]);

$ch = curl_init('https://backfireapi.base44.app/functions/forward');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('BACKFIRE_KEY'),
        'Content-Type: application/json',
    ],
]);

$envelope = json_decode(curl_exec($ch), true);
curl_close($ch);

if (!$envelope['ok']) {
    throw new RuntimeException($envelope['error']['code']);
}
echo $envelope['body']['text'];

Questions about this

Other languages

Try it with 5,000 free trips.

No card, no subscription, and the balance never expires.