定制 soc-warden/php-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

soc-warden/php-sdk

Composer 安装命令:

composer require soc-warden/php-sdk

包简介

SOCWarden security observability SDK for PHP (framework-agnostic)

README 文档

README

Framework-agnostic PHP SDK for SOCWarden security observability. Works with any PHP 8.2+ application -- no Laravel or Symfony dependency required.

Installation

composer require soc-warden/php-sdk

Quick Start

use SOCWarden\SOCWarden;

$soc = new SOCWarden(
    apiKey:   'your-api-key',
    endpoint: 'https://ingestor.socwarden.com',
);

// Simple tracking with named arguments
$soc->track('auth.login.success', actorId: 'usr_123', actorEmail: 'john@example.com');

// Track with metadata
$soc->track('data.exported', actorId: 'usr_456', metadata: ['format' => 'csv', 'rows' => 1500]);

Fluent Event Builder

$soc->event('auth.login.failure')
    ->actorEmail('john@example.com')
    ->ip('203.0.113.42')
    ->meta('reason', 'invalid_password')
    ->meta('attempt', 3)
    ->send();

$soc->event('data.exported')
    ->actor('usr_123', 'john@example.com')
    ->resource('Report', 42)
    ->metadata(['format' => 'csv', 'rows' => 1500])
    ->timestamp(new \DateTimeImmutable())
    ->severity('medium')
    ->send();

Raw Data Array

$soc->trackData('auth.login.success', [
    'actor_id'    => 'usr_123',
    'actor_email' => 'john@example.com',
    'ip'          => '203.0.113.42',
    'user_agent'  => 'Mozilla/5.0 ...',
    'metadata'    => ['role' => 'admin'],
]);

PSR-15 Middleware (Slim, Mezzio, etc.)

The SDK ships with a PSR-15 middleware that automatically captures request context (method, path, query string, IP, user agent, referer) and attaches it to every tracked event.

Slim 4

use SOCWarden\SOCWarden;
use SOCWarden\Middleware\PSR15Middleware;
use Slim\Factory\AppFactory;

$soc = new SOCWarden(
    apiKey:   'your-api-key',
    endpoint: 'https://ingestor.socwarden.com',
);

$app = AppFactory::create();
$app->add(new PSR15Middleware($soc));

$app->post('/login', function ($request, $response) use ($soc) {
    // Request context is automatically captured
    $soc->track('auth.login.success', actorId: $userId);
    // ...
});

Mezzio (Laminas)

// config/pipeline.php
$app->pipe(new \SOCWarden\Middleware\PSR15Middleware($container->get(\SOCWarden\SOCWarden::class)));

Manual Request Context

If you are not using PSR-15 middleware, you can set the request manually:

// Any PSR-7 ServerRequestInterface
$soc->setRequest($psrRequest);

// Now all tracked events include request context
$soc->track('auth.login.success', actorId: 'usr_123');

Constructor Options

Parameter Type Default Description
apiKey string (required) Your SOCWarden API key
endpoint string (required) SOCWarden ingestor base URL
timeout int 5 HTTP timeout in seconds
autoContext bool true Auto-collect server/request context
browserContextHeader string X-SOCWarden-Context Header for browser-side context JSON

Auto-Context

When autoContext is enabled (default), every event automatically includes:

  • SDK info: name (socwarden-php), version
  • Server info: hostname, PHP version, PID
  • Request info (when a PSR-7 request is set): method, path, sanitized query string, referer, origin, content type, accept language, request ID
  • Browser context: parsed from the X-SOCWarden-Context header (set by the browser SDK)

Sensitive query string parameters (token, key, password, secret, code, auth, session, csrf) are automatically redacted.

Rate Limit Handling

The SDK automatically handles HTTP 429 responses with file-based backoff:

  • On 429, the SDK backs off for 1 hour (or the server's Retry-After value)
  • During backoff, a probe request is sent every 5 minutes to check if quota is restored
  • On success, the backoff is automatically cleared
  • Backoff state is stored in sys_get_temp_dir() so it persists across requests

Event Type Format

Event types must match the pattern: ^[a-z][a-z0-9]{0,29}(\.[a-z][a-z0-9_]{0,29}){1,3}$

Examples: auth.login.success, data.exported, server.ssh.login.failure

License

MIT

soc-warden/php-sdk 适用场景与选型建议

soc-warden/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 soc-warden/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 soc-warden/php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 soc-warden/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-12