PHP library for Api Stats Portal
Installation via composer: composer require 4apps/api-stats-php
Usage example (for php 8.1+):
use 4Apps\ApiStats;
$mongoDbConfig = [
'string' => 'mongodb://mongodb:27017',
'dbname' => 'apiStatistics'
];
$apiStats = ApiStats($mongoDbConfig);
// Create event
$eventId = $apiStats->logApiStatistics($scope, $service, $contextName, $methodName, $endpointUrl);
// Failed
$apiStats->updateApiStatistics($eventId, failed: true);
// Retry
$seconds = 60; // Retry timeout
$apiStats->updateApiStatistics($eventId, retry: true, retrySeconds: $seconds);
// Success
$apiStats->updateApiStatistics($eventId);
// Custom timestamp
$apiStats->updateApiStatistics($eventId, timestamp: time());
To make changes to the library do this:
python3 -m pip install -r requirements.txt
fab docker.install
docker compose exec develop bash
- Repository contains configuration files for vscode container extension.
To run phpunit tests, bring up development docker machine and run phpunit: ./vendor/bin/phpunit