xiaosongshu / rtmp_server
A RTMP live streaming server written in PHP
v2.0.4
2026-05-26 13:58 UTC
Requires
- php: >=8.1
- ext-zlib: *
- apix/log: ^1.2
- evenement/evenement: ^3.0
- phpbg/mpegts: ^0.2.0
- react/promise: ^2.9
README
π¨π³ δΈζ β’ π¬π§ English
A pure PHP-based RTMP live streaming server. Supports RTMP push and pull streaming, FLV streaming (HTTP/WS), HLS streaming, and includes a simple web-based player.Features
- π₯ RTMP push & pull streaming
- π‘ HTTP-FLV and WebSocket-FLV pull streaming
- π§© HLS output (M3U8 + TS segments)
- π₯οΈ Built-in simple web player (FLV / HLS)
- π³ Docker development environment (includes FFmpeg and PHP extensions)
- β‘ Pure PHP implementation β no Nginx or other streaming server required
Requirements
- PHP >= 8.1 (CLI mode)
- PHP extensions:
socketsand others (see error messages if missing)
Quick Start
Installation
composer create-project xiaosongshu/rtmp_server
Configuration & Startup
Option 1: Using phpstudy (recommended for beginners)
- Download and install phpstudy
- Switch PHP version to 8.1
- Install required extensions via phpstudy's package manager (follow any error prompts)
- Navigate to the project root and start the server
Option 2: Using Docker (recommended β includes all dependencies)
Run the following command in the project root:
docker-compose up -d
The Docker environment includes PHP 8.1, all required extensions, and FFmpeg (for pushing streams, packet inspection, or transcoding).
Start the Server
php server.php
Stop the Server
- Windows:
Ctrl + C - Linux / macOS:
kill -9 <PID>(find PID withps aux | grep server.php)
Port Configuration
Default ports (can be modified in the entry file):
| Port | Service |
|---|---|
| 1935 | RTMP |
| 8501 | FLV (HTTP & WebSocket) |
| 80 | Web (HLS + static pages) |
Push Streaming
Push Stream URL
rtmp://127.0.0.1:1935/a/b
a= application nameb= stream key / channel name
(customizable; only letters and numbers allowed)
Push Streaming Tools
OBS Studio
- Download: obsproject.com
- Tutorial: OBS streaming to custom RTMP server
FFmpeg
ffmpeg -re -stream_loop 1 -i "movie.mp4" -vcodec h264 -acodec aac -f flv rtmp://127.0.0.1/a/b
Parameter explanation:
| Parameter | Description |
|---|---|
-re |
Read input at native frame rate |
-stream_loop 1 |
Loop the input file once |
-i "movie.mp4" |
Input video file |
-vcodec h264 |
H.264 video encoding |
-acodec aac |
AAC audio encoding |
-f flv |
FLV output format (required for RTMP) |
Pull Streaming
Available Pull URLs
| Protocol | URL |
|---|---|
| RTMP | rtmp://127.0.0.1/a/b |
| HTTP-FLV | http://127.0.0.1:8501/a/b.flv |
| WebSocket-FLV | ws://127.0.0.1:8501/a/b.flv |
| HLS (M3U8) | http://127.0.0.1:80/hls/a/b/index.m3u8 |
Players
- VLC media player β Open Network Stream
- Built-in web player:
- FLV test page: http://127.0.0.1:80/index.html
- HLS test page: http://127.0.0.1:80/play.html
Troubleshooting
- Missing extensions at runtime: This project runs in PHP CLI mode, which differs from traditional FPM mode. Install the required extensions based on any error messages. If using Docker, all extensions are pre-installed.
- Port conflicts: Check if ports 1935, 8501, or 80 are already in use. You can modify the port configuration in the entry file. If you change the ports, remember to update the built-in player pages accordingly.
β οΈ Disclaimer
- Some code or materials in this project may originate from public sources. If there are any copyright concerns, please contact me for removal.
- This project is fully open source, intended for technical sharing and mutual progress. The author is not responsible for any legal or commercial disputes arising from individual usage.
- Users assume all risks associated with using this project, including but not limited to copyright and compliance issues.
For any questions or suggestions, feel free to reach out via email.
Contact
π§ Email: 2723659854@qq.com