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.
Download xiaosongshu/rtmp_server
More information about xiaosongshu/rtmp_server
Files in xiaosongshu/rtmp_server
Package rtmp_server
Short Description Native PHP RTMP live server with FLV/HLS, MP4 slicing, PHP client, relay & gateway and webrtc server
License Apache-2.0
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
eventextension 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
- Quick Start
- Push/Pull Stream Address Specification
- Live & VOD Access URLs
- Page/Script Usage Guide
- Project Directory Structure
- System Overall Architecture
- Port Constants Configuration
- Recording Task Switch Configuration
- Multiâprocess Worker Configuration (IPC Stream Sync Core)
- Push Stream Authentication Configuration
- FLV Live Distribution Gateway
- Static File HTTP Gateway
- Multiâmethod Push/Pull Stream Access Tutorial
- Live Relay/Forwarding Tutorial
- Cluster Deployment Architecture for 100,000+ Concurrent Users
- Multiâbitrate Support
- WEBRTC
- FAQ
- License
- Companion Toolkits
-
Contact
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.ymlfile; rundocker-compose up -dto 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
- Realâtime screen push:
http://127.0.0.1/push.html - Loop push of local MP4/FLV files:
http://127.0.0.1/flv_push.html
Method 2: FFmpeg standard push
Method 3: OBS Studio push
- Server:
rtmp://127.0.0.1:1935/live/ - Stream Key:
stream
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 |
- Because long-duration live broadcasts generate large FLV files, directly transcoding them to MP4 may exhaust system memory. The system only automatically processes files smaller than 500 MB.for larger files, please transcode manually.
- Alternatively, you can use the toolkit
xiaosongshu/flv2mp4to manually convert FLV to MP4.
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
-
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.
-
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.
-
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.
- 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
- 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.
- Windows: although
SO_REUSEADDRis 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. - Internal IPC ports are externally accessible for pull streams, useful for manual load balancing on Windows.
Platform Performance Limitations
- Linux: epoll I/O model â a single process can handle thousands of concurrent long connections; multiâprocess can fully utilise multiâcore CPUs â the preferred choice for production.
- Windows: the underlying select model has a very low concurrency limit (about 256 connections per process) â only for local development and debugging; do not deploy in production.
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:
-
RTMP
- OBS stream key:
stream?key=live_123456 -
HTTP-FLV
- WS-FLV PHP client
Security Best Practices
- Replace default keys with random strings of 32+ characters.
- Enable HTTPS/WSS in public deployments to prevent plainâtext key sniffing.
- Rotate stream keys periodically to reduce leakage risk.
- 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)
- Multiâpath push: Streamers can push simultaneously to multiple origin nodes (e.g., nodes A, B, C); if any node fails, others still hold the stream, and viewers experience no interruption.
- Automatic failover on pusher side: OBS/FFmpeg can be configured with backup push URLs for activeâstandby switching; webâside can use JavaScript to push to multiple paths.
2. Origin Node Cluster (Stream Production Core)
- Activeâactive deployment: All origin nodes are active and can accept pushes; they synchronise stream data with each other via
forward.php, ensuring each origin node holds a complete stream copy. - Automatic failover: If any origin node goes down, others continue to serve, and the relay sync links automatically reconnect â business continues without interruption.
- Parallel recording: Each origin node independently performs FLV/fMP4/HLS recording, creating multiple physical backups to prevent singleâpoint storage loss.
3. Edge Node Cluster (Stream Distribution & Cache)
- Nearestâpull: Edge nodes pull live streams from origin nodes via
forward.php, cache GOP keyâframes, and provide lowâlatency, instantâstart playback to viewers. - Elastic scaling: Edge nodes can be dynamically added or removed based on concurrent load, supporting horizontal scaling (e.g., for traffic spikes).
- Flexible role switching: Origin and edge nodes use the same codebase; they can be promoted to origin (accept pushes) or demoted to edge (pullâonly distribution) at any time via configuration, allowing onâdemand resource allocation.
4. Gateway Distribution Layer
- flvGateway cluster: Designed specifically for HTTPâFLV/WSâFLV realâtime streams â no transcoding, pure forwarding, with GOP caching for instant startâup; supports multiâlevel cascading and horizontal scaling to handle massive player connections.
- fileGateway cluster: Independently hosts HLS segments, MP4 VOD files, static pages, etc., separating these from dynamic stream services to prevent file I/O from blocking live services.
5. Viewer Terminals
- Multiâprotocol coverage: Supports RTMP, HTTPâFLV, WSâFLV, HLS, compatible with PC, mobile, Web, and all platforms.
- Smart scheduling: Uses DNS roundârobin, Nginx reverse proxy, or global load balancing (GSLB) to direct viewer requests to the nearest or leastâloaded edge node, ensuring optimal experience.
6. Data Flow
- Push: Streamer â (multiâpath) â Origin node cluster â
forwardsync to all origin nodes. - Pull (edge): Edge node â
forwardpulls from any origin node â cache â serves local viewers. - Playback: Viewer â load balancer â flvGateway/fileGateway â edge node (or origin) â stream data.
- Recording: All nodes (origin/edge) record according to configuration, eventually merging to MP4 for VOD playback.
7. Disaster Recovery and Backup Mechanisms
- Nodeâlevel disaster recovery: If any single node (origin or edge) fails, the forwarding client automatically reconnects to other live nodes â stream data is not interrupted.
- Regionâlevel disaster recovery: If an entire data centre goes down, DNS can be switched to a backup data centre (requires deploying multiple clusters) for crossâregion high availability.
- Recording backup: Each node stores its own recording files; for important streams, multiple nodes can record simultaneously to ensure data is not lost.
8. Scalability and Concurrency Capability
- Horizontal scaling: All layers support horizontal scaling â adding nodes immediately shares the load without restarting existing services.
- 100k+ concurrency: Edge nodes and gateway layers can scale horizontally on a large scale; combined with CDN edge acceleration, they can support 100,000+ concurrent viewers (bandwidth and server resources must be provisioned accordingly).
- Performance optimisation: driven by the event extension (epoll) on Linux; a single node can handle thousands of longâlived connections (depending on actual server configuration), and multiânode clusters linearly improve concurrency.
9. Deployment Recommendations
-
Stream synchronisation between nodes is accomplished via the builtâin
forward.phprelay client. This tool can pull RTMP/HTTPâFLV/WSâFLV streams from any source and push them to one or multiple target nodes simultaneously, carrying authentication parameters (e.g., key) when pushing. Developers can write scheduling scripts based on actual network topology and business needs (e.g., combining health checks, loadâbalancing strategies, or business rules) to dynamically configure pull source addresses, target node lists, and forwarding parameters, thus achieving automated stream synchronisation between nodes. Role switching between origin and edge nodes also relies on external scheduling logic: it is recommended to monitor node system status (CPU load, memory usage, active connections, number of push streams, etc.) or external traffic allocation policies to trigger scripts that dynamically adjust node roles, enabling elastic scaling, failover, and disaster recovery. The entire scheduling system can be customised according to actual scenarios, providing a highly flexible productionâready deployment solution.
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/flv2mp4toolkit, 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:
- đ Version requirement: this feature requires
xiaosongshu/flv2mp4version >= 1.4.4. - đ The
xiaosongshu/flv2mp4toolkit supports FLV/MP4 and FLVâtoâHLS reâencoding with watermarking. For more usage, refer to its documentation.
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_IPto the server's public IP; otherwise clients cannot connect correctly.- Ensure firewall allows
WS_PORT(TCP) andUDP_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.1for 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:
- Enter the signaling address (default
ws://127.0.0.1:8088) and a room ID (e.g.,stream_001). - Click "Start Push"; the browser will pop up a screen/desktop selection window; choose the screen or tab to share, and check "Share audio" if system audio is needed.
- After successful push, the page shows a local preview and prints
â ć¨ćľä¸(or its English equivalent, but the page itself may be in Chinese).
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:
- Enter the signaling address (default
ws://127.0.0.1:8088) and the room ID (must match the pusher). - Click "Start Watching"; the page automatically initiates a WHEP pull request.
- After successful pull, the video renders automatically and displays playback statistics (bitrate, packet loss, etc.).
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
- Public IP setting: Ensure
PUBLIC_IPinconfig/app.phpis set to the actual public IP; otherwise, the generated SDP will contain an internal IP, causing connection failures. - Firewall: Open TCP port (WS_PORT) and the UDP port .
- STUN server: This project includes a simple builtâin STUN service that only supports basic NAT type detection. If clients are behind symmetric NAT, consider configuring a public TURN server (requires custom extension).
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?
- The push bitrate or resolution is too high â lower them and test again.
- The server CPU is saturated â enable multiâprocess to utilise multiple cores.
- Under high concurrency, the FLV gateway is not deployed â too many player connections consume origin resources.
- 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
- Email: [email protected]
- GitHub: https://github.com/2723659854
All versions of rtmp_server with dependencies
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