PHP

The Fanar PHP client sends payloads over HTTP. Call the static methods anywhere in your code — controllers, services, console commands, or jobs.

Installation

composer require fanar-app/fanar

Helper function

The fanar() helper infers the type automatically — the same way the Node.js client does.

fanar('request received');              // log
fanar(['user' => $user, 'cart' => $cart]); // object — JSON tree
fanar($e);                                 // exception — stack trace

fanar($order, ['label' => 'new order', 'project' => 'shop']);

Static API

Use the static methods when you need explicit control over the payload type.

<?php
use Fanar\Fanar;

Fanar::log('request received');
Fanar::dump(['user' => $user, 'orders' => $orders]);
Fanar::exception($e);

Methods

MethodDescription
Fanar::log($value)Send a string, number, or boolean as a log entry
Fanar::dump($value)Send any value — rendered as a collapsible tree
Fanar::exception($e)Send a Throwable with full stack trace; origin is taken from the throw site

All methods accept an optional second argument for metadata:

Fanar::log('hello', ['label' => 'boot', 'project' => 'auth']);

Named timers

Measure any block of code with a named timer. Call stop() to send the elapsed time to the app. Calling stop() more than once is safe.

<?php
use Fanar\Fanar;

$t = Fanar::time('import');
importProducts($csv);
$t->stop();

Configuration

By default the client connects to localhost:23517. Configure once at boot time.

<?php
use Fanar\Fanar;

Fanar::configure([
  'host'    => '192.168.1.5',
  'port'    => 9913,
  'enabled' => true,
]);