liquidrazor/posix-runtime 问题修复 & 功能扩展

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

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

liquidrazor/posix-runtime

Composer 安装命令:

composer require liquidrazor/posix-runtime

包简介

POSIX runtime primitives for isolated worker execution in LiquidRazor.

README 文档

README

liquidrazor/posix-runtime is a small PHP 8.3+ library that provides POSIX runtime primitives for isolated worker execution.

It is transport-agnostic process-control infrastructure for the LiquidRazor micro-kernel lifecycle. It does not implement HTTP, CLI, queue, gRPC, routing, DI, logging, scheduling, or daemon management.

Requirements

  • PHP 8.3+
  • ext-posix
  • ext-pcntl

Missing required extensions are treated as runtime failures. The library does not silently degrade to PID-only supervision.

What It Ships

Current public surface:

  • immutable value objects under include/Value
  • enums under include/Enum
  • typed exceptions under include/Exception
  • public contracts under include/Contract
  • a thin public facade: LiquidRazor\PosixRuntime\PosixRuntime

Current runtime behavior:

  • worker identity generation
  • worker process metadata before and after fork
  • centralized POSIX/PCNTL adapter boundary
  • raw wait-status interpretation
  • signal handler registration
  • pending-signal dispatch
  • child execution wrapping
  • parent-side worker supervision
  • graceful shutdown requests
  • forced termination escalation

What It Does Not Ship

This library does not implement:

  • transport kernels
  • framework bootstrapping
  • event manager infrastructure
  • process event catalogs
  • service containers
  • schedulers
  • external process-manager replacement behavior

Higher-level kernels are expected to plug into the runtime lifecycle exposed here.

Public API

The main entry point is LiquidRazor\PosixRuntime\PosixRuntime.

It currently exposes:

  • capabilityStatus(): RuntimeCapabilityStatus
  • assertAvailable(): void
  • run(WorkerExecutionRequest $request): SupervisionResult
  • shutdown(WorkerProcessMetadata $metadata, ShutdownRequest $request): SupervisionResult

Typical value types involved in public calls:

  • WorkerId
  • WorkerIdentity
  • ProcessId
  • WorkerProcessMetadata
  • WorkerExecutionRequest
  • WorkerExecutionResult
  • WorkerExitStatus
  • ShutdownRequest
  • SupervisionResult

Example

<?php

declare(strict_types=1);

use LiquidRazor\PosixRuntime\Include\Value\ProcessId;
use LiquidRazor\PosixRuntime\Include\Value\WorkerExecutionRequest;
use LiquidRazor\PosixRuntime\Include\Value\WorkerId;
use LiquidRazor\PosixRuntime\Include\Value\WorkerIdentity;
use LiquidRazor\PosixRuntime\Include\Value\WorkerProcessMetadata;
use LiquidRazor\PosixRuntime\PosixRuntime;

$runtime = new PosixRuntime();

$request = new WorkerExecutionRequest(
    WorkerProcessMetadata::prepare(
        new WorkerIdentity(new WorkerId('example-worker'), 'example-worker'),
        new ProcessId(posix_getpid()),
    ),
    static fn (): int => 0,
);

$result = $runtime->run($request);

SupervisionResult contains:

  • the final WorkerExecutionResult
  • an optional ShutdownRequest
  • a forcedTermination flag

Lifecycle Model

The implemented lifecycle is:

Parent prepares worker metadata
Parent forks worker

Parent path:
    receive child PID
    supervise with waitpid()
    dispatch pending signals
    interpret final status
    return structured result

Child path:
    install child-local signal handlers
    execute callback
    exit with explicit code

The runtime currently models these worker states:

  • Prepared
  • Spawned
  • Running
  • Finished
  • Crashed
  • ShutdownRequested
  • Terminated
  • ForcedTermination

Termination reasons are modeled separately:

  • Completed
  • NonZeroExit
  • Signal
  • ShutdownRequested
  • ForcedTermination
  • Crash

Signal Handling

The runtime currently supports explicit registration and dispatch of:

  • SIGTERM
  • SIGINT
  • SIGQUIT when supported by the platform
  • SIGCHLD

Signal behavior is explicit:

  • handlers are registered through dedicated services
  • pending signals are dispatched deliberately
  • child-local termination handlers re-signal with the default handler so parent supervision sees signal termination correctly

Supervision And Shutdown

Parent-side supervision is driven by waitpid() through the adapter layer.

Implemented outcomes include:

  • successful completion
  • non-zero exit
  • signal termination
  • shutdown-requested completion
  • forced termination

Shutdown coordination currently supports:

  1. send graceful signal
  2. wait until timeout
  3. escalate to forced signal when required

Failure Model

The library uses typed exceptions for meaningful runtime failures, including:

  • MissingPosixExtension
  • MissingPcntlExtension
  • RuntimeUnavailable
  • ForkFailed
  • SignalRegistrationFailed
  • InvalidWorkerStateTransition
  • WorkerExecutionFailed
  • WorkerCrashed
  • WorkerTerminatedBySignal
  • WaitOperationFailed
  • ShutdownTimeoutExceeded
  • ForcedTerminationFailed

Structured results are used for normal process outcomes. Exceptions are reserved for unavailable runtime capabilities or failed control operations.

Directory Layout

include/
  Contract/
  Enum/
  Exception/
  Value/

lib/
  Runtime/
  Signal/
  Supervision/

src/
  PosixRuntime.php

tests/

Dependency direction is strict:

include <- lib <- src

Testing

The current PHPUnit suite covers:

  • value-model invariants
  • capability detection
  • adapter failure mapping
  • exit-status interpretation
  • signal registration and dispatch
  • spawn and child execution
  • parent-side supervision
  • graceful shutdown
  • forced termination escalation
  • public facade wiring

Process tests skip cleanly when POSIX support is unavailable and include defensive child cleanup to avoid zombie processes.

License

MIT

liquidrazor/posix-runtime 适用场景与选型建议

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

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

围绕 liquidrazor/posix-runtime 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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