xiaosongshu/rtmp_server

A RTMP live streaming server written in PHP

Maintainers

Package info

github.com/2723659854/rtmp-server

Type:project

pkg:composer/xiaosongshu/rtmp_server

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

v2.0.4 2026-05-26 13:58 UTC

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: sockets and others (see error messages if missing)

Quick Start

Installation

composer create-project xiaosongshu/rtmp_server

Configuration & Startup

Option 1: Using phpstudy (recommended for beginners)

  1. Download and install phpstudy
  2. Switch PHP version to 8.1
  3. Install required extensions via phpstudy's package manager (follow any error prompts)
  4. 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 with ps 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 name
  • b = stream key / channel name
    (customizable; only letters and numbers allowed)

Push Streaming Tools

OBS Studio

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

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