NexPHP:程式碼更精簡、功能更強且不靠魔法的次世代 PHP 框架
NexPHP – Next-gen PHP framework with Less Code, More Power, and Zero Magic
NexPHP 是為現代 PHP 執行環境及 AI 輔助編碼設計的框架,採用嚴格型別、明確屬性,並支援 FrankenPHP 和長駐工作程序。持續工作程序模式的基準測試約達 218,000 req/sec,經過 10,000 次請求測試後記憶體增長為 0.00 MB。框架亦內置佇列、排程、安全及可觀測性功能。
Why I Built NexPHP: Modern PHP with Less Code, More Power, and Zero Magic
PHP in 2026 is unrecognizable from what it was a decade ago. With PHP 8.3+, strict types, enums, readonly properties, attributes, and Fibers, the language itself has become one of the fastest, most reliable backends on the web.
Yet, many framework ecosystems still rely on architectural conventions invented in 2011:
- Facades and global state.
- Dynamic magic methods that confuse static analysis and AI coding tools.
- Architecture solely centered on the classic FPM "shared-nothing" model.
That is why I created NexPHP: a modern framework designed from scratch around two realities:
- Modern runtimes (FrankenPHP and long-lived persistent workers).
- AI-assisted "vibe-coding" (where explicit types and zero magic lead to effortless AI collaboration).
The Core Principles
1. Zero Magic, Strict Types
No hidden metaprogramming. If a controller action expects a validated request, you simply typehint your FormRequest subclass:
#[Post('/products')]
public function store(CreateProductRequest $request): ResponseInterface
{
// $request is automatically resolved, validated, and injected.
// If validation fails, a 422 JSON response is returned automatically.
$data = $request->validated();
return new JsonResponse(['status' => 'created'], 201);
}
Because everything has explicit types and attributes, AI models (Cursor, Windsurf, Copilot) generate working code on the first attempt without guessing.
2. Dual-Runtime Readiness
In persistent worker mode, PHP keeps the application in memory. If not designed carefully, user identity or database state can leak across requests.
NexPHP features built-in request-scope isolation:
- Singletons live across the worker lifetime.
- Scoped bindings (current user, request, CSRF) are automatically wiped via
$app->forgetScoped()after each response.
In benchmarks, NexPHP achieves:
- ~218,000 req/sec in persistent worker mode.
- 0.00 MB memory growth over a 10,000-request soak test.
3. Native Fiber Concurrency
No complex asynchronous event loops. You can run concurrent I/O operations cooperatively using PHP Fibers:
use Nex\Concurrency\Scheduler;
$scheduler = new Scheduler();
$results = $scheduler->all([
'user' => fn () => $httpClient->get('https://api.example.com/user'),
'order' => fn () => $httpClient->get('https://api.example.com/order'),
]);
4. Full-Stack Services Included
NexPHP includes everything needed for production SaaS applications:
- Queues: Database-backed queue with exponential retry backoff and failed-job dead-letter stores.
-
Scheduler: Cron-like DSL (
dailyAt('02:00')) with lock-based overlap prevention. - Security: Sliding-window rate limiting, CSRF verification, and CORS preflight handling.
-
Observability: PSR-3 structured JSON logging with automatic secret redaction (
password,token), and Prometheus metrics exporter.
Try It Out in 30 Seconds
You can start a new project right now via Composer:
composer create-project nexphp/nexphp my-api
cd my-api
php bin/nex serve
- GitHub Repository: https://github.com/snigdho5/nexphp
- Packagist: https://packagist.org/packages/nexphp/nexphp
I’d love to hear your thoughts, feedback, and pull requests!
來源:DEV Community · dev.to