lescopr/lescopr-php
Composer 安装命令:
composer require lescopr/lescopr-php
包简介
Lescopr PHP SDK - Zero-configuration monitoring for PHP applications. Auto-captures logs, errors and metrics from Laravel, Symfony and vanilla PHP projects.
关键字:
README 文档
README
Lescopr is a zero-configuration PHP monitoring SDK that automatically captures logs, errors, and exceptions from any PHP project and streams them in real-time to the Lescopr app.
Works out of the box with Laravel, Symfony, and vanilla PHP / custom OOP projects.
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Framework Integration
- Architecture
- CLI Reference
- Advanced Configuration
- Packagist
- License
Features
- ✅ Automatic error capture — hooks into
set_error_handler,set_exception_handler,register_shutdown_function - ✅ Framework auto-detection — detects Laravel, Symfony, Lumen, Slim, and vanilla PHP from
composer.json - ✅ Monolog integration — drop-in handler for Laravel and Symfony
- ✅ Background daemon — runs as a
pcntl_forkprocess, completely non-blocking - ✅ HTTP batch transport — logs are batched and flushed every 5 seconds via HTTPS
- ✅ Zero configuration — a single CLI command is enough to get started
- ✅ Works everywhere — Laravel, Symfony, Lumen, Slim, scripts, custom OOP
Requirements
| Requirement | Version |
|---|---|
| PHP | ≥ 7.4 |
| Composer | ≥ 2.0 |
guzzlehttp/guzzle |
^6.5 || ^7.0 |
symfony/console |
^4.4 || ^5.0 || ^6.0 || ^7.0 |
ext-json |
bundled with PHP |
ext-pcntl |
Recommended (for daemon) |
ext-posix |
Recommended (for daemon) |
ext-openssl |
Recommended (for HTTPS) |
Note:
ext-pcntlis not available on Windows. On those environments the SDK operates in direct HTTP mode (no background daemon).
Installation
composer require lescopr/lescopr-php
Quick Start
Step 1 — Initialise the SDK in your project directory:
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY
This auto-detects your framework, registers the project with the Lescopr API, writes .lescopr.json, and starts the background daemon.
Step 2 — Integrate into your application (see Framework Integration below).
That's it. All logs and exceptions are forwarded to the Lescopr app automatically.
Framework Integration
Laravel
The SDK registers automatically via Composer's package auto-discovery. No manual registration needed.
Publish the config (optional):
php artisan vendor:publish --tag=lescopr-config
Add the Lescopr channel to your logging stack in config/logging.php:
'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['single', 'lescopr'], // ← add 'lescopr' ], 'lescopr' => [ 'driver' => 'monolog', 'handler' => \Lescopr\Integrations\Laravel\Logging\LescoprMonologHandler::class, 'handler_with' => [ 'sdk' => app(\Lescopr\Core\Lescopr::class), ], ], ],
All Log::info(...), Log::error(...) etc. calls are automatically forwarded to Lescopr.
Exceptions are captured automatically via the exception handler decorator bundled with the ServiceProvider.
Environment variables (.env):
LESCOPR_SDK_KEY=lsk_xxxx LESCOPR_API_KEY=lak_xxxx LESCOPR_ENVIRONMENT=production
Symfony
Register the bundle in config/bundles.php:
return [ // ... other bundles Lescopr\Integrations\Symfony\LescoprBundle::class => ['all' => true], ];
Wire the Monolog handler in config/packages/monolog.yaml:
monolog: handlers: lescopr: type: service id: Lescopr\Integrations\Symfony\LescoprMonologHandler channels: ['!event', '!doctrine']
Register services in config/services.yaml:
services: Lescopr\Core\Lescopr: factory: ['Lescopr\Core\Lescopr', 'fromConfig'] public: true Lescopr\Integrations\Symfony\LescoprMonologHandler: arguments: ['@Lescopr\Core\Lescopr'] Lescopr\Integrations\Symfony\EventSubscriber\KernelExceptionSubscriber: arguments: ['@Lescopr\Core\Lescopr'] tags: - { name: kernel.event_subscriber }
Kernel exceptions are automatically captured via KernelExceptionSubscriber.
Vanilla PHP / POO
Add one line at the top of your entry point (index.php / bootstrap.php):
<?php require 'vendor/autoload.php'; \Lescopr\Integrations\Vanilla\LescoprBootstrap::init(); // Your existing code continues unchanged
The bootstrap installs:
set_error_handler— captures all PHP errors (E_WARNING, E_NOTICE, etc.)set_exception_handler— captures uncaught exceptionsregister_shutdown_function— captures fatal errors (E_ERROR, E_PARSE, etc.)
Manual configuration (no .lescopr.json):
\Lescopr\Integrations\Vanilla\LescoprBootstrap::init([ 'sdk_key' => 'lsk_xxxx', 'api_key' => 'lak_xxxx', 'environment' => 'production', 'debug' => false, ]);
Architecture
Your PHP Application
│
│ Log::error() / throw Exception / trigger_error()
▼
┌─────────────────────────────────┐
│ LescoprMonologHandler │ (Monolog — Laravel / Symfony)
│ OR LescoprBootstrap handlers │ (set_error_handler — Vanilla)
└──────────────┬──────────────────┘
│ HTTP POST (batched)
▼
┌─────────────────────────────────┐
│ Lescopr Daemon │ (background process, .lescopr.pid)
│ pcntl_fork → DaemonRunner │ flushes every 5 seconds
└──────────────┬──────────────────┘
│ HTTPS batch
▼
https://api.lescopr.com
│
▼
Lescopr App
https://app.lescopr.com
Key components:
| Component | Path | Role |
|---|---|---|
Lescopr (core) |
src/Core/Lescopr.php |
Central SDK object, config, log queue, daemon lifecycle |
DaemonRunner |
src/Core/DaemonRunner.php |
Background process — flushes logs, sends heartbeats |
ProjectAnalyzer |
src/Filesystem/Analyzers/ProjectAnalyzer.php |
Scans project, detects frameworks |
FrameworkAnalyzer |
src/Filesystem/Analyzers/FrameworkAnalyzer.php |
Detects Laravel, Symfony, Lumen, Slim, POO |
HttpClient |
src/Network/HttpClient.php |
HTTPS transport via Guzzle |
LescoprServiceProvider |
src/Integrations/Laravel/ |
Auto-registers in Laravel |
LescoprBundle |
src/Integrations/Symfony/ |
Registers in Symfony DI container |
LescoprBootstrap |
src/Integrations/Vanilla/ |
One-line bootstrap for plain PHP |
| CLI | bin/lescopr |
init, start, stop, status, diagnose, reset |
CLI Reference
After installation, the lescopr command is available via Composer's vendor/bin:
./vendor/bin/lescopr [COMMAND] [OPTIONS]
| Command | Description |
|---|---|
init --sdk-key KEY |
Initialise the SDK in the current project |
start |
Start the monitoring daemon |
stop |
Stop the monitoring daemon |
status |
Show daemon status and project info |
diagnose [--details] [--check-server] |
Run a full diagnostic |
reset [--force] [--keep-config] |
Remove SDK configuration and stop daemon |
init
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY [--environment production] [--no-start-daemon]
- Auto-detects your project framework
- Registers the project with the Lescopr API
- Writes
.lescopr.json - Starts the background daemon (use
--no-start-daemonto skip)
diagnose
./vendor/bin/lescopr diagnose --details --check-server
Prints PHP environment, configuration validity, daemon state, and optionally tests HTTPS connectivity to api.lescopr.com.
Advanced Configuration
.lescopr.json is generated automatically by lescopr init:
{
"sdk_id": "proj_xxxx",
"sdk_key": "lsk_xxxx",
"api_key": "lak_xxxx",
"environment": "development",
"project_name": "my-app",
"project_stack": ["laravel"]
}
Security: Add
.lescopr.jsonto your.gitignore.
Environment variables
| Variable | Description |
|---|---|
LESCOPR_SDK_KEY |
SDK key (overrides .lescopr.json) |
LESCOPR_API_KEY |
API key (overrides .lescopr.json) |
LESCOPR_ENVIRONMENT |
development or production |
LESCOPR_DAEMON_MODE=true |
Prevents the SDK from forking inside its own daemon |
LESCOPR_DEBUG=true |
Enables verbose output to .lescopr.log |
Packagist
The package is available on Packagist: lescopr/lescopr-php
To publish a new release, use the automated release script:
# From the sdk/php directory
./scripts/release.sh 0.2.0
This will update CHANGELOG.md, commit, tag and push — GitHub Actions will create the GitHub Release and notify Packagist automatically.
For the full publishing guide (Symfony Flex recipe, Laravel News, SemVer rules), see PUBLISHING.md.
Support
| Channel | Link |
|---|---|
| 📖 Documentation | https://lescopr.com/docs |
| 🌐 App | https://app.lescopr.com |
| support@lescopr.com | |
| 🐛 Bug reports | https://github.com/Lescopr/lescopr-php/issues |
License
lescopr/lescopr-php 适用场景与选型建议
lescopr/lescopr-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「symfony」 「performance」 「php」 「debugging」 「monitoring」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lescopr/lescopr-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lescopr/lescopr-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lescopr/lescopr-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
The bundle for easy using json-rpc api on your project
Create link to static resources with cache-breaking segment based on md5 of the file
A Zend Framework module that sets up Monolog for logging in applications.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-07