api-analytics/php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

api-analytics/php

最新稳定版本:v0.1.0

Composer 安装命令:

composer require api-analytics/php

包简介

API Analytics middleware for native PHP applications.

README 文档

README

A free and lightweight API analytics solution, complete with a dashboard.

Getting Started

1. Generate an API key

Head to apianalytics.dev/generate to generate your unique API key with a single click. This key is used to monitor your specific API and should be stored privately.

2. Install the package

composer require api-analytics/php

3. Add analytics to your API

<?php

require_once 'vendor/autoload.php';

use ApiAnalytics\Core\Config;
use ApiAnalytics\PHP\Analytics;

$analytics = new Analytics('your-api-key');

// Start timing
$startTime = microtime(true);

// Your API logic here
$response = ['message' => 'Hello World!'];
$statusCode = 200;

// Calculate response time in milliseconds
$responseTimeMs = (int) round((microtime(true) - $startTime) * 1000);

// Log the request
$analytics->log($_SERVER, $responseTimeMs, $statusCode);

// Send response
header('Content-Type: application/json');
http_response_code($statusCode);
echo json_encode($response);

4. View your analytics

Your API will now log and store incoming request data on all routes. View your analytics at apianalytics.dev/dashboard.

Customisation

Custom mapping functions can override the default behaviour:

use ApiAnalytics\Core\Config;
use ApiAnalytics\PHP\Analytics;

$config = new Config();

// Custom IP extraction
$config->setGetIpAddress(function (array $ctx) {
    return $ctx['HTTP_X_REAL_IP'] ?? $ctx['REMOTE_ADDR'] ?? null;
});

// Custom user ID from API key header
$config->setGetUserId(function (array $ctx) {
    return $ctx['HTTP_X_API_KEY'] ?? null;
});

$analytics = new Analytics('your-api-key', $config);

Privacy Levels

Control IP address handling:

  • 0 - IP stored, location inferred (default)
  • 1 - Location inferred, IP discarded
  • 2 - IP never sent
$config = new Config();
$config->privacyLevel = 2;

Self-Hosting

For self-hosted instances:

$config = new Config();
$config->serverUrl = 'https://your-server.com/';

$analytics = new Analytics('your-api-key', $config);

More Information

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固