Download the PHP package xiaosongshu/rtmp_server without Composer

On this page you can find all versions of the php package xiaosongshu/rtmp_server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package rtmp_server

RTMP Server

🇨🇳 中文文档 • 🇬🇧 English Docs

A pure PHP self-developed RTMP live streaming service, zero dependency on third-party streaming media tools like FFmpeg and Nginx, enabling rapid setup of private live streaming platforms out of the box. On Linux, the event extension is automatically enabled for epoll event-driven I/O; on Windows, it gracefully degrades to the select I/O model, ensuring full platform compatibility. Project positioning: underlying infrastructure – complete self-developed RTMP/HTTP-FLV/WS-FLV/WEBRTC protocol stacks and asynchronous network engine; business management, authentication, playback, and other upper-layer applications need to be extended by developers. The project supports H.264 decoding + scaling + watermarking + encoding, and can re-encode FLV, MP4, and HLS at different bitrates to adapt to various network environments and devices.


Table of Contents

Environment Dependencies

Dependency Hard Requirement Description
PHP >= 8.1, CLI mode only, FPM not supported
sockets extension Mandatory – foundation for underlying TCP/WS/RTMP communication
event extension Highly recommended on Linux – enables epoll high‑concurrency event model; on Windows, if missing, it automatically falls back to select

Quick environment setup: the project includes a docker-compose.yml file; run docker-compose up -d to spin up the complete runtime environment with one command.


Quick Start

1. Project Installation

2. Start the Origin Main Service

Example successful startup output:

3. Quick Push Stream Test

Method 1: Browser‑based push without additional software

Method 2: FFmpeg standard push

Method 3: OBS Studio push

Method 4: Built‑in PHP push client

4. Quick Playback

Open in browser: http://127.0.0.1/index.html


Push/Pull Stream Address Specification

Push URLs (Unified for OBS/FFmpeg/PHP/Web)

Protocol Standard Format Example
RTMP rtmp://host:1935/{app}/{stream} rtmp://127.0.0.1:1935/live/stream
HTTP-FLV http://host:8501/{app}/{stream} http://127.0.0.1:8501/live/stream
WebSocket-FLV ws://host:8501/{app}/{stream} ws://127.0.0.1:8501/live/stream

Field constraints: {app} (application name) and {stream} (channel name) allow only English letters, digits, and underscores; special characters and Chinese are prohibited.

Live & VOD Access URLs

Real‑time Live Playback URLs

Protocol Access URL Use Case
RTMP rtmp://127.0.0.1:1935/live/stream ffplay, desktop professional players
HTTP-FLV http://127.0.0.1:8501/live/stream.flv Low‑latency live on PC browsers
WebSocket-FLV ws://127.0.0.1:8501/live/stream.flv Native WebSocket MSE playback in browsers
HLS-TS http://127.0.0.1:80/hls/live/stream/index.m3u8 Mobile devices, WeChat built‑in browser
HLS-FMP4 (audio‑video merged segments) http://127.0.0.1:80/mp4/live/stream/output_merge/index.m3u8 Mainstream desktop browsers, mobile, WeChat built‑in browser, ffplay, VLC, etc.
HLS-FMP4 (audio‑video separate segments) http://127.0.0.1:80/mp4/live/stream/output_separate/index.m3u8 Mainstream desktop browsers, mobile, WeChat built‑in browser, ffplay, VLC, etc.

Recorded VOD Playback URLs

Recorded files are persistently stored under the project root; complete files are automatically generated after the live stream ends:

File Type Storage Path Access Example
Standard transcoded MP4 mp4/live/stream/index.mp4 http://127.0.0.1/mp4/live/stream/index.mp4
Raw FLV recording flv/live/stream/index.flv http://127.0.0.1/flv/live/stream/index.flv
HLS TS segment directory hls/live/stream/index.m3u8 http://127.0.0.1:80/hls/live/stream/index.m3u8
HLS-FMP4 audio‑video merged segments mp4/live/stream/output_merge/index.m3u8 http://127.0.0.1:80/mp4/live/stream/output_merge/index.m3u8
HLS-FMP4 audio‑video separate segments mp4/live/stream/output_separate/index.m3u8 http://127.0.0.1:80/mp4/live/stream/output_separate/index.m3u8

Page/Script Usage Guide

Live/VOD Playback Pages

Page File Description Access URL
index.html HTTP-FLV low‑latency live player http://127.0.0.1/index.html
play.html HLS mobile‑adapted player http://127.0.0.1/play.html
mp4.html MP4 VOD dedicated page http://127.0.0.1/mp4.html
video.html FLV VOD player http://127.0.0.1/video.html
play_merge.html fMP4 segment live/VOD page (native JS) http://127.0.0.1/play_merge.html
mse.html fMP4 segment live/VOD page (hls.js) http://127.0.0.1/mse.html

Web‑based Push Pages

Page File Description Access URL
push.html Browser screen capture push (WS-FLV) http://127.0.0.1/push.html
flv_push.html Loop push of local MP4/FLV files http://127.0.0.1/flv_push.html
push_merge.html Multi‑stream composition push http://127.0.0.1/push_merge.html
push_transcode.html Frontend multi‑bitrate transcoding push for weak networks http://127.0.0.1/push_transcode.html

Built‑in PHP Push/Pull Client Scripts

Script Function Example Command
pusher.php Command‑line file push client php pusher.php video.mp4 http://127.0.0.1:8501/live/stream
puller.php Command‑line pull/record client php puller.php http://127.0.0.1:8501/live/stream.flv output.flv

Built‑in PHP Relay Client Scripts

Script Function Example Command
forward.php Command‑line live data relay client php forward.php ws://127.0.0.1:8501/a/b.flv rtmp://127.0.0.1:1935/c/d

Built‑in PHP Gateway Client Scripts

Script Function Example Command
fileGateway.php Command‑line file gateway client php fileGateway.php 0.0.0.0 8100
flvGateway.php Command‑line FLV gateway client php flvGateway.php 8080 http://127.0.0.1:8501

PHP Live Startup Script

Script Function Example Command
server.php Start live service from command line php server.php

Project Directory Structure


System Overall Architecture

Architecture Detailed Description

  1. Origin Main Service (sole stream producer) All external pushes are ingested by the origin, which handles protocol parsing, authentication, multi‑format transmuxing, and parallel recording; the three recording tasks (FLV recording, fMP4 slicing, HLS slicing) are completely isolated threads that do not block each other. In low‑concurrency scenarios, the built‑in port 80 static service can be used directly without deploying additional gateways.

  2. FLV Live Distribution Gateway No transcoding logic – only traffic forwarding and GOP key‑frame caching for instant startup on players; supports horizontal scaling and multi‑level cascading (recommended at most two levels in production, as more levels increase latency); Linux epoll for high concurrency, Windows for testing only. In high‑concurrency scenarios, all player pull requests go through the gateway, reducing connection pressure on the origin main process.

  3. Static File Gateway Cluster Dedicated to hosting static resources such as HLS, MP4, FLV, and frontend pages, achieving read‑write separation; must be deployed for large‑scale VOD scenarios to prevent file I/O from saturating the origin.

  4. Integrated Live Tooling The project supports pure‑PHP client push, pull, and live relay, and provides web‑based push, playback, transcoding, and stream composition. It supports single‑process/multi‑process switching and the personalised media toolkit xiaosongshu/flv2mp4.

Deployment Recommendations by Concurrency

Concurrency Level Recommended Deployment
Low concurrency (< 1000 online viewers) Only start the origin server.php, using built‑in ports 80 and 8501 – no gateways needed.
Medium concurrency (1000 ~ 5000 online) Origin + single‑layer FLV gateway cluster + single‑layer static file gateway cluster, with Nginx load balancing.
High concurrency / large‑scale events (>5000 online) Origin + multi‑layer FLV gateway and static gateway clusters, front‑end load balancing; for 10k+ events, commercial CDN edge distribution is mandatory – do not let a single server handle all traffic.

Port Constants Configuration

Modify config/app.php to adjust global service ports. Built‑in constants:

Recording Task Switch Configuration

config/app.php independently controls three recording tasks without interference:

Multi‑process Worker Configuration (IPC Stream Sync Core)

Principle

Under PHP CLI multi‑process model, each worker process has isolated memory. When a single process receives a push stream, other workers cannot access the stream data, so stream sync via IPC (Inter‑Process Communication) is mandatory. This project does not use traditional system IPC like shared memory or pipes. Instead, it implements a custom local TCP Socket IPC scheme: it allocates a set of internal communication ports; the worker that receives the stream actively forwards the complete stream data to all other workers via the built‑in TCP client, achieving full‑process stream data sharing.

Configuration in config/app.php

When multi‑process is disabled (ENABLE_MULTI_PROCESS=false), the worker count and internal communication port configuration become invalid; the service runs in single‑process mode with no IPC stream sync.

Multi‑process Port Load‑balancing Rules

  1. Linux: the system supports port reuse (SO_REUSEPORT), allowing multiple workers to listen on the main FLV port 8501 simultaneously; the kernel automatically distributes player connections among workers.
  2. Windows: although SO_REUSEADDR is supported, new TCP connections will only be assigned to the first process that bound to port 8501 – native load balancing is not available; you can use Nginx reverse‑proxy to the internal communication ports (8502+) to distribute traffic.
  3. Internal IPC ports are externally accessible for pull streams, useful for manual load balancing on Windows.

Platform Performance Limitations

Push Stream Authentication Configuration

Description

Prevents unauthorised streams from overwriting live channels; only push requests carrying a valid stream key are accepted. Playback pull currently has no built‑in authentication; developers can implement referer/token validation at the gateway or reverse‑proxy layer. Configuration file config/auth.php:

Authenticated Push URL Format

Carry the key via the URL parameter key:

  1. RTMP

  2. OBS stream key: stream?key=live_123456
  3. HTTP-FLV

  4. WS-FLV PHP client

Security Best Practices

  1. Replace default keys with random strings of 32+ characters.
  2. Enable HTTPS/WSS in public deployments to prevent plain‑text key sniffing.
  3. Rotate stream keys periodically to reduce leakage risk.
  4. Authentication is disabled by default; enable it if needed.

Note: any change to the above configuration requires a service restart to take effect.


FLV Live Distribution Gateway

Overview

A lightweight traffic forwarding service that pulls HTTP‑FLV/WS‑FLV streams from the upstream origin, caches GOP key‑frames for instant player start‑up; supports horizontal scaling and multi‑level cascading to offload the origin. The gateway can pull from either HTTP‑FLV or WS‑FLV sources and uniformly provides both HTTP‑FLV and WS‑FLV playback addresses.

Startup Commands

Gateway Playback URL Format

Example: http://127.0.0.1:8080/live/stream.flv

Static File HTTP Gateway

Overview

An independent static resource HTTP service that hosts HLS, MP4, FLV, and frontend pages, separating file I/O from live streaming to improve stability under high‑concurrency VOD loads.

Startup Commands

Nginx Load‑Balancing Reverse Proxy Example

Resource Access Examples

Multi‑method Push/Pull Stream Access Tutorial

RTMP Push

OBS, FFmpeg, and PHP clients all support the standard RTMP protocol. Address format: rtmp://host:1935/{app}/{stream}

HTTP‑FLV Push

Suitable for command‑line and automated programmatic push. Address: http://host:8501/{app}/{stream}

WebSocket‑FLV Push

Native browser push solution, with latency as low as 50ms. Use the built‑in push.html page.

PHP Pull Script

For server‑side pull backup and cross‑server relay:

Live Relay/Forwarding Tutorial

This project provides live relay functionality, allowing you to forward a live stream to multiple servers, supporting rtmp/ws‑flv/http‑flv protocols for both pull and push. For detailed command usage, see forward.php. Example relay command:

The above command forwards the stream from http://127.0.0.1:8501/a/b.flv to rtmp://127.0.0.1:1935/c/d, ws://127.0.0.1:8501/c/e, and http://127.0.0.1:8501/c/f. You can also push to any other platform that supports RTMP, WS‑FLV, or HTTP‑FLV.

Engineering Suggestions

pusher.php / puller.php / forward.php can be integrated into custom scripts to automate pull‑relay, backup recording, etc., without relying on third‑party tools, completing a full PHP live streaming business loop.


Cluster Deployment Architecture for 100,000+ Concurrent Users


Core Architecture Design Notes

1. Push Layer High Availability (Disaster Recovery)

2. Origin Node Cluster (Stream Production Core)

3. Edge Node Cluster (Stream Distribution & Cache)

4. Gateway Distribution Layer

5. Viewer Terminals

6. Data Flow

  1. Push: Streamer → (multi‑path) → Origin node cluster → forward sync to all origin nodes.
  2. Pull (edge): Edge node → forward pulls from any origin node → cache → serves local viewers.
  3. Playback: Viewer → load balancer → flvGateway/fileGateway → edge node (or origin) → stream data.
  4. Recording: All nodes (origin/edge) record according to configuration, eventually merging to MP4 for VOD playback.

7. Disaster Recovery and Backup Mechanisms

8. Scalability and Concurrency Capability

9. Deployment Recommendations

Multi‑bitrate Support

This project includes built‑in multi‑bitrate transcoding capability, supporting conversion of Baseline Profile FLV files into multi‑resolution HLS streams to adapt to different network environments and mobile devices.

⚠️ Performance Limitation Notice

  • The current multi‑bitrate module is implemented in pure PHP and is performance‑constrained – suitable only for small offline transcoding or functional validation.
  • Since H.264 re‑encoding is compute‑intensive and time‑consuming, it is strictly prohibited for use in production live streaming. For professional adaptive bitrate transcoding, please use mature tools like FFmpeg.
  • 📌 This feature depends on the xiaosongshu/flv2mp4 toolkit, which is already installed with this project – no extra action is needed.

How to Use

Refer to the example in encode.php for detailed configuration. Run the following command to transcode FLV to HLS:


Applicable Scenarios

Scenario Recommended
Local testing / functional validation ✅ Recommended
Small offline file transcoding (< 10 MB) ✅ Usable
Real‑time live stream transcoding ❌ Not recommended
High‑concurrency / large‑scale production ❌ Strictly prohibited

Note: This module is for learning and communication only – do not use in production. For high‑performance transcoding, consider using FFmpeg or specialised transcoding services.


Watermark Tool

You can use the built‑in tool to generate a text watermark. See watermark.php for detailed configuration. Generate a watermark file with:

The system already provides a sample watermark file watermark_80x16.


WEBRTC

This project includes a built‑in standalone WebRTC service based on pure PHP, implementing WHIP (WebRTC HTTP Ingest Protocol) push and WHEP (WebRTC HTTP Egress Protocol) pull, supporting zero‑plugin, ultra‑low‑latency (<500ms) real‑time audio/video transmission in browsers. It also provides DataChannel chat functionality for live interaction, messaging, etc.


Access Method Use Case Protocol DataChannel Support
WebSocket signaling Built‑in pages (push.html / play.html / index.html) Custom JSON signaling + SRTP ✅ Yes
Standard WHIP/WHEP Third‑party clients (OBS, FFmpeg, etc.) and whip.html / whep.html HTTP POST + SDP ❌ No

⚠️ Note: The WebRTC service and the RTMP main service are independent of each other and must be started as separate processes. Once the WebRTC service is started, it will automatically feed live data into the RTMP server. You can then directly pull the stream from the RTMP server for viewing, as well as utilize automatic screen recording and transcoding.

Features

Feature Description
WebSocket signaling push Provides webrtc/push.html, uses WebSocket signaling + SRTP media, supports DataChannel chat
WebSocket signaling pull Provides webrtc/play.html, uses WebSocket signaling + SRTP media, supports DataChannel chat
DataChannel testing Provides webrtc/index.html for standalone DataChannel communication testing
Standard WHIP push Supports standard WHIP (HTTP POST), compatible with third‑party clients; provides whip.html test page
Standard WHEP pull Supports standard WHEP (HTTP POST), compatible with third‑party players; provides whep.html test page
Transport protocol SRTP/SRTCP over UDP, low latency, packet‑loss resilient
Audio/Video codecs Video H.264, audio Opus (natively supported by browsers)
Signaling service Built‑in WebSocket signaling server (for WS method) and WHIP/WHEP HTTP endpoints (for standard protocols)
Independent deployment Isolated ports from RTMP main service, lightweight resource usage, can be started/stopped independently

Starting the Service

In the project root, run:

Successful startup example:

Run silently in background (Linux):


Service Ports and Configuration

WebRTC uses independent port constants defined in config/app.php:

Important:

  • For public deployment, you must set PUBLIC_IP to the server's public IP; otherwise clients cannot connect correctly.
  • Ensure firewall allows WS_PORT (TCP) and UDP_PORT (UDP), otherwise media transport fails.
  • If clients and server are on the same private network, you can use the private IP or 127.0.0.1 for testing.

Push Guide

(The following uses local testing; for production, replace with public addresses. The WS signaling server automatically handles WebRTC‑related HTTP requests on the default port 8088.)

1. Browser Screen Push (Recommended)

Visit built‑in page: http://{server_ip}:8088/push.html

Steps:

2. WHIP Standard Client Push

If using a third‑party WHIP client (e.g., OBS WebRTC plugin, FFmpeg WHIP output), the push address is:

Refer to the respective client documentation for configuration. The built‑in whip.html page at http://{server_ip}:8088/whip.html can also be used.

3. DataChannel Chat Integration

In the push page (push.html), after connection is established, a DataChannel is automatically created. You can send messages in the chat box at the bottom; messages will be forwarded by the server to all clients in the same room.


Playback Guide

1. Browser Low‑latency Pull

Visit built‑in page: http://{server_ip}:8088/play.html

Steps:

2. Generic WHEP Client

Any WHEP‑compatible player can use the address:

The built‑in whep.html page at http://{server_ip}:8088/whep.html can also be used.

3. DataChannel Chat Interaction

In the playback page (play.html), after connection is established, a DataChannel is automatically created. You can send messages in the chat box at the bottom; messages will be forwarded by the server to all clients in the same room.


Advanced Configuration and Tuning

1. Multi‑process Support

The WebRTC service currently does not have built‑in multi‑process load balancing, but you can start multiple instances on different ports and use Nginx reverse proxy for horizontal scaling (pay attention to UDP port allocation).

2. Public Deployment Considerations


Related Pages and Scripts

File Function Access / Usage
webrtc/push.html Browser screen push (with DataChannel) http://127.0.0.1:8088/push.html
webrtc/play.html Browser low‑latency pull (with DataChannel) http://127.0.0.1:8088/play.html
webrtc/whep.html Browser WHEP pull player http://127.0.0.1:8088/whep.html
webrtc/whip.html WHIP push test page (video only) http://127.0.0.1:8088/whip.html
webrtc/index.html DataChannel chat lobby http://127.0.0.1:8088/index.html
webrtc.php WebRTC service startup script php webrtc.php

FAQ

Q1: What to do if Windows says the event extension is missing?

Windows does not have the event extension; the service automatically switches to the select I/O model. Only the sockets extension is required – no extra handling is needed.

Q2: How to verify the service started successfully?

The terminal prints three listening logs: RTMP 1935, FLV 8501, and static port 80 – success.

Q3: Push succeeds but playback stutters continuously?

  1. The push bitrate or resolution is too high – lower them and test again.
  2. The server CPU is saturated – enable multi‑process to utilise multiple cores.
  3. Under high concurrency, the FLV gateway is not deployed – too many player connections consume origin resources.
  4. Insufficient server upstream bandwidth – limit the number of concurrent viewers.

Q4: How to stop the service?

Press Ctrl + C in the terminal to send a termination signal, or simply close the terminal window.

Q5: Which third‑party push software is supported?

Fully compatible with standard RTMP clients: OBS Studio, FFmpeg, xSplit, mobile RTMP SDKs.

Q6: How do the WebRTC and RTMP main services work together?

They are completely independent and do not affect each other. You can start or stop either service as needed, allowing both RTMP and WebRTC protocol stacks to coexist.

License

This project is licensed under the Apache License 2.0. The software is provided "as is", without warranty of any kind, express or implied. The developer shall not be liable for any direct, indirect, or consequential damages arising from the use of this program. For the full terms, see the LICENSE file in the project root.

Companion Toolkits

The underlying codec and stream format conversion capabilities are independently packaged as xiaosongshu/flv2mp4. It provides FLV/MP4/fMP4/HLS inter‑conversion, standalone push/pull clients, and gateway components, and can be integrated into third‑party PHP projects.

Contact


All versions of rtmp_server with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
react/promise Version ^2.9
evenement/evenement Version ^3.0
apix/log Version ^1.2
ext-zlib Version *
xiaosongshu/webrtc Version ^1.0
xiaosongshu/flv2mp4 Version ^1.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xiaosongshu/rtmp_server contains the following files

Loading the files please wait ...