---
title: "PHP"
description: "Send events with cURL."
canonical_url: "https://docs.logstrace.dev/guides/integrations/php"
---
# PHP

> Send events with cURL.

```php [logstrace.php]
<?php

function logstrace(array $events): void
{
    $ch = curl_init('https://logstrace.dev/api/ingest');
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . getenv('LOGSTRACE_KEY'),
            'Content-Type: application/json',
        ],
        CURLOPT_POSTFIELDS => json_encode(['events' => $events]),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 5,
    ]);
    curl_exec($ch);
    curl_close($ch);
}
```

```php
logstrace([
    ['channel' => 'orders', 'text' => "Order {$order->id} paid {$order->total} {$order->currency} by {$order->method}"],
]);
```

Using Monolog? Its JSON records use `message`, `level_name`, `datetime` and `context`. Map `level_name` → `level`, `datetime` → `ts` and `context` → `data` before sending (`message` is accepted as is).


## Sitemap

See the full [sitemap](https://docs.logstrace.dev/sitemap.md) for all pages.
