Building a real-time streaming platform is usually associated with complex infrastructures and expensive services.
However, in this case, I developed a fully functional live streaming system using PHP, WordPress, and WebRTC — all inside a custom plugin.
This is a real-world implementation, not a theoretical example.
Project Goal
The main idea was to create a platform where:
Users can watch live streams
Private sessions can be started between users
Real-time chat is available
A pay-per-minute system is implemented
All without relying on external streaming services.
⚙️ Tech Stack
Backend: PHP (WordPress plugin)
Database: MySQL ($wpdb)
Streaming: WebRTC (PeerJS)
Frontend: JavaScript + AJAX
Real-Time Streaming with WebRTC
The core of the system is based on WebRTC using PeerJS.
The broadcaster (model) shares their camera:
navigator.mediaDevices.getUserMedia({ video: true, audio: true });
The viewer connects using a dummy stream to avoid permission prompts:
function createDummyStream() {
const canvas = document.createElement('canvas');
return canvas.captureStream();
}
This approach significantly improves UX.
Private Sessions Logic
Private sessions are handled via URL parameters:
/transmision-privada?babe=username
Flow:
User selects a model
A direct peer connection is created
The session starts in real time
Disconnection is detected automatically
💸 Pay-Per-Minute System
One of the most important parts is monetization.
Users are charged per minute
Balance is updated in real time
Broadcasters receive a percentage
Example logic:
function charge_user_per_minute($user_id) {
$balance = get_user_meta($user_id, 'balance', true);
return $balance - 3000;
}
This allows building scalable revenue models.
Real-Time Chat (AJAX)
Instead of using WebSockets, I implemented chat using AJAX polling:
Messages sent via admin-ajax.php
Fetched every few seconds
Rendered dynamically
Simple, but effective.
Stream State Management
A custom table tracks active streams:
active_private
active_public
finished
This allows listing live streams and controlling sessions.
Role-Based Access
Two main roles:
Broadcasters (models)
Subscribers (users)
Managed directly through WordPress roles.
Real-World Implementation
This architecture is already being used in production in a live webcam streaming platform with direct payment system, where all these concepts are applied together.
It combines real-time video, chat, and monetization in a single environment.
Final Thoughts
Building a streaming platform with PHP and WordPress is absolutely possible if you combine the right tools.
The real challenge is not just streaming video — it's integrating:
- Real-time communication
- Payment logic
- User roles
- System state
This project proves that you can build complex, scalable systems without leaving the WordPress ecosystem.
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.