-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_api.php
More file actions
27 lines (20 loc) · 773 Bytes
/
Copy pathexample_api.php
File metadata and controls
27 lines (20 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
require_once __DIR__ . '/vendor/autoload.php';
use GreenCode\EcoProfiler;
use GreenCode\ConfigLoader;
use GreenCode\Providers\StaticProvider;
use GreenCode\Exporters\MemoryExporter;
// Chargement configuration
$carbonData = ConfigLoader::load('carbon_data');
$settings = ConfigLoader::load('settings');
// Initialisation Stateless
$provider = new StaticProvider($carbonData['averages']);
$profiler = new EcoProfiler($provider, $settings, new MemoryExporter());
$profiler->start();
// Simulation d'une route API
usleep(15000);
// Récupération du rapport sans aucune écriture disque
$report = $profiler->stop('FR', ['mysql_query' => 5]);
// Sortie JSON pour réponse API
header('Content-Type: application/json');
echo json_encode($report, JSON_PRETTY_PRINT);