PHPTS Docs

PHPTS「事件触发任务」是什么?

一句话:它让 PHP 在 Windows 上拥有了「长连接 + 事件驱动」的能力——WebSocket、TCP、MQTT、串口、定时器五类事件源由一个 Rust 网关统一持有,每来一个事件就委托 PHP 执行一次脚本,应答原路返回。PHP 开发者不用写常驻进程、不用碰 socket,照旧写「收输入、处理、echo 输出」的普通脚本即可。PHP 无论运行在 HTTP 请求、命令行还是事件任务中,均可向客户端主动推送消息。

事件触发任务 AI 编程指南

面向 AI 编程工具的 PHPTS 「事件触发任务」PHP 脚本编写与「Server → Client 主动推送」规范:五类事件脚本模板、PHPTS_EVENT_* 元数据、输出与关闭约定、共用推送接口及完整调用示例。教 AI 编程工具如何去写对应的 PHP 代码,并让用户了解整个「事件触发任务」的生命周期流程。

PHPTS 2.0.13 Update: New Event-Triggered Tasks

Released on November 19, 2026, PHPTS 2.0.13 adds the Event-Triggered Tasks module: WebSocket, TCP, MQTT, serial port, and timer event sources are unified through the built-in Rust event gateway, and PHP scripts handle events and reply on the same channel. With the phpts_kv inter-process shared key-value store and the Server → Client push interface, any ordinary PHP page can push messages to online clients, TCP connections, or serial ports. This article covers a three-minute quick start, script conventions, the push loop, timer re-entrancy prevention, and five debugging assistants.

version