amphp

Writing non-blocking, async PHP code using the AMPHP framework — revolt/event-loop, amphp/amp ^3, and the full amphp/* ecosystem (http-server, http-client, websocket, mysql, redis, parallel, socket, pipeline, file, cache, sync, dns, process). Always use this skill when PHP code involves: amphp/* packages, the Revolt event loop, Amp\Future, Amp\async(), Amp\delay(), PHP Fibers for async I/O, DeferredFuture, TimeoutCancellation, SocketHttpServer, WebsocketClientHandler, or Worker\Task. Also use when the user wants to replace blocking PHP (curl_exec, file_get_contents, PDO, sleep) with AMPHP async equivalents, build a non-blocking PHP HTTP or WebSocket server, run concurrent PHP I/O without pcntl, or debug Revolt event-loop behavior — even if they don't say "amphp" explicitly but the context clearly points to this ecosystem.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "amphp" with this command: npx skills add rekryt/amphp

AMPHP v3 Skill

Version

This skill covers AMPHP v3 onlyamphp/amp ^3, revolt/event-loop ^1, PHP 8.1+.

If you see v2 patterns (yield $promise, Amp\Loop::run(), Promise, Coroutine), treat them as wrong and rewrite using v3 equivalents. See docs/v2-v3.md for the full migration table.


Non-Negotiable Rules

These apply to every file you write or modify in an AMPHP project:

  • Always add declare(strict_types=1) at the top of every PHP file.
  • Always pass JSON_THROW_ON_ERROR to every json_encode / json_decode call.
  • Never use blocking I/O (file_get_contents, PDO, curl_exec, sleep) inside the event loop — use async equivalents from amphp/file, amphp/mysql, amphp/http-client, Amp\delay().
  • Always release mutex/semaphore locks in a finally block — exceptions skip cleanup otherwise.
  • Always buffer() or fully iterate HTTP response bodies — unread bodies block connection reuse.

For the full list of 19+ documented gotchas (buffer deadlocks, channel EOF, arrow function capture, Redis factory vs constructor, etc.), read docs/common-mistakes.md before writing async code.


Reference Files

Load only the file(s) relevant to the task. Do not load all files at once.

Docs

FileWhen to load
docs/constructors.mdInstantiating any AMPHP class — verified constructor signatures, param names, defaults, and factory methods
docs/namespaces.mdWriting use imports — complete namespace paths for every class, function, and enum
docs/packages.mdStarting a new project or adding a dependency — composer require commands and package overview
docs/common-mistakes.mdBefore writing any async code — 19+ real bugs with wrong/correct examples
docs/v2-v3.mdMigrating from AMPHP v2 or encountering yield/Promise/Coroutine patterns

Examples

FileWhen to load
examples/core-async.mdEventLoop bootstrap, async(), delay(), Future combinators (await, awaitAll, awaitAny), DeferredFuture
examples/cancellation.mdTimeoutCancellation, DeferredCancellation, CompositeCancellation, propagating cancellation
examples/sync.mdLocalMutex, LocalSemaphore, LocalParcel, Barrier, LocalKeyedMutex, RateLimitingSemaphore, synchronized()
examples/http-server.mdMinimal server, Router with route params, Middleware stack, TLS, Sessions, Static files, proxy setup
examples/http-client.mdGET/POST, parallel requests, ConnectionLimitingPool, interceptors, proxy, streaming response body
examples/websocket.mdEcho server, push-only with drain pattern, broadcast gateway, WS client, streaming binary messages
examples/byte-stream.mdReadableBuffer, pipe(), GZIP compress/decompress, Base64 encode/decode, splitLines()
examples/pipelines.mdQueue back-pressure, Pipeline operators (map, filter, tap), concurrent(), merge(), concat()
examples/parallel.mdTask interface, fan-out with worker pool, IPC Channel progress reporting, ChannelException handling
examples/database.mdMySQL connection pool, transactions, prepared statements; Redis get/set/hash/pubsub/cache
examples/file-io.mdFile\read/write/exists/getSize/openFile/listFiles/deleteDirectory/createDirectoryRecursively
examples/cache.mdLocalCache (LRU + TTL), AtomicCache (compute-if-absent), PrefixCache, NullCache
examples/interval.mdInterval repeating timer, enable/disable, weakClosure() to prevent GC cycles, EventLoop::delay/repeat/cancel
examples/testing.mdAsyncTestCase, constructing mock Request objects, League\Uri\Http::new(), phpunit CLI flags

Workflows

FileWhen to load
workflows/http-server-full.mdBuilding a complete HTTP server from scratch: Router + Middleware + Static files + WebSocket + graceful shutdown
workflows/parallel-fan-out.mdCPU-bound workload split across multiple worker processes with IPC progress reporting
workflows/tcp-server.mdRaw TCP server: echo, custom binary protocol, TLS mutual auth, graceful shutdown

Templates

FileWhen to load
templates/http-server.phpCopy-paste boilerplate for a full HTTP server (Router + Middleware + Static files + graceful shutdown)
templates/websocket-handler.phpCopy-paste boilerplate for WebSocket handlers: echo, push-only, broadcast gateway
templates/parallel-task.phpCopy-paste boilerplate for a worker Task class with IPC progress + fan-out orchestration

Scripts

FileUsage
scripts/server-demo.phpphp scripts/server-demo.php [--port=N] — run a minimal HTTP server to verify setup
scripts/http-client-demo.phpphp scripts/http-client-demo.php [url] — demo GET, parallel requests, ConnectionLimitingPool

Resources

FileWhen to load
resources/blocking-vs-async.mdQuick lookup: mapping every common blocking PHP function to its AMPHP v3 async replacement

Legacy

FileContents
references/advanced-patterns.mdDeep dives: fiber model internals, all Future combinators, Queue back-pressure mechanics, Pipeline concurrency, Cancellation semantics, EventLoop timer details
references/class-examples.mdOne minimal usage example per key AMPHP class, organized by package

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

Dlazy One Click Generation

Short-video generation pipeline. Configure subject, script, TTS voiceover, BGM, and subtitle styling.

Registry SourceRecently Updated
Coding

Dlazy Video Generate

Video generation skill. Automatically selects the best dlazy CLI video model based on the prompt.

Registry SourceRecently Updated
Coding

Dlazy Audio Generate

Audio generation skill. Automatically selects the best dlazy CLI audio/TTS model based on the prompt. 音频生成技能。根据提示词自动选择最佳的 dlazy CLI 音频/TTS 模型。

Registry SourceRecently Updated
Coding

Dlazy Vidu Audio Clone

Clone voice and generate new text reading audio with one click using Vidu Audio Clone.

Registry SourceRecently Updated