Build a Real-Time Douyin Live Ranking Service with PHP, Node.js, and Workerman
This guide walks you through setting up a Douyin live‑room ranking service using PHP 8.1+, Node.js 16+, Composer, and Workerman, covering required tools, installation steps, parameter configuration for room_id or live_id with cookies, and how to launch and preview the real‑time WebSocket server.
⚠️ Disclaimer This project is developed for learning and research purposes only; any illegal or platform‑violating use is strictly prohibited. Users assume all risks as detailed in the DISCLAIMER.md file.
Introduction
Required Tools
PHP 8.1+ : Core language for HTTP requests and data parsing.
Node.js 16+ : Handles WebSocket real‑time connections.
Composer : PHP dependency manager.
NPM : Node.js package manager.
Server environment : Linux or Windows, supports Workerman (PHP process manager).
Usage
1. Install Node.js dependencies
Navigate to the node directory and run: npm install After the packages are installed, start the server with: node server.js This runs two JavaScript files required for the WebSocket service.
2. Install PHP dependencies
In the project root, execute: composer install This installs all PHP libraries defined in composer.json.
3. Configure parameters
Edit start.php in the root directory and set the three required parameters. There are two ways to provide them:
Method 1 – Only room_id : Open Douyin in a browser, log in, enter any live room, press F12 to view source, search for roomid (usually the 8th occurrence) and copy the value.
Method 2 – live_id and cookie : live_id is the numeric string after the URL of a live room. To obtain the cookie, open Douyin, enter a live room, press F12, refresh, then copy the cookie value from the request headers.
4. Start the service
From the project root, run: php start.php The script launches Workerman workers and establishes a WebSocket connection to Douyin.
Preview
---------------------------------------------- WORKERMAN -----------------------------------------------
Workerman/5.1.3 PHP/8.1.13 (JIT off) Windows NT/10.0
----------------------------------------------- WORKERS ------------------------------------------------
worker listen processes status
none none 1 [ok]
【√】WebSocket 连接成功.
【直播间排行榜msg】: , : , :
【直播间统计msg】短显示: 368, 中显示: 368, 长显示: 368 在线观众
【进场msg】[111111][女]用*** 进入了直播间
【统计msg】当前观看人数: 354, 累计观看人数: 20.9万
... (additional real‑time messages showing audience entries and likes) ...Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
