Files
ytplayer/alt/swoole

ytplayer Swoole backend

Drop-in PHP 8.3 / Swoole 5 alternative for the existing frontend/. It is intentionally dependency-light: Swoole's coroutine HTTP server, PDO SQLite, SQLite WAL, cURL-free coroutine HTTP calls for InnerTube, and yt-dlp/ffmpeg subprocesses. Unimplemented optional APIs return the app-compatible 501 JSON response.

Build and run

Build context is the repository root so the image copies the unmodified frontend:

docker build -f alt/swoole/Dockerfile -t ytplayer-swoole .
docker compose -f alt/swoole/docker-compose.yml up -d --build

The Compose service exposes only container port 3000 on the external dokploy-network; it has no host port mapping or router labels. Mount/point MEDIA_VOLUME_MARKER at an existing marker file on the media volume if that disk is removable. MEDIA_CACHE_MAX_BYTES, DB_PATH, MEDIA_DIR, and PORT are configurable. The data volume stores SQLite WAL and <videoId>.<generation>.mp4/.m4a files.

For a local A/B run, map a host port in a temporary override (do not add that mapping to the committed production Compose file), then use node alt/compare.mjs http://bun-host:3000 with ALT_URL=http://127.0.0.1:3000. Set VIDEO_ID to an id already cached on both backends for Range and download parity. The compare.mjs script compares response status, selected headers, and JSON key paths without requiring result bodies to be byte-identical.

Browser and performance checks

Open the Swoole URL in Chromium and exercise search, playback, Save to device, offline shell installation, and profile sync. For endpoint parity run:

ALT_URL=http://127.0.0.1:3000 VIDEO_ID=abcdefghijk node alt/compare.mjs http://127.0.0.1:3001
ALT_URL=http://127.0.0.1:3000 VIDEO_ID=abcdefghijk node alt/swoole/bench.mjs

The bench script runs 1/10/50/200 concurrent clients against version, a static CSS file, a cache-hit search, and a cached-file byte range. It prints p50/p95, request rate, and transfer bytes as JSON. Results must be recorded in BENCH.md from the same host and dataset for both backends.

Current verification boundary

php -l and the pure-PHP manifest smoke checks can run on a host without Swoole. The host used to author this backend did not have ext-swoole, pdo_sqlite, or a Docker daemon; no HTTP server, Playwright browser run, or performance numbers are claimed until the image is built and run on a Swoole-capable host.