Would it be okay to work with pseudo streaming in php?

As far as I know that php blocks the file system (block I/o)

This means that if a user with a weak Internet and pull a video through the php interpreter, others will not be able to run the script in order to pull the right for a video. And I'm counting on 1,000 hear in a moment. Below script code php. he pulls at 1024 bytes and makes echo in the html5 player where the data type mp4.
Directly to give stat.file don't want, using Nginx or ffserver too. I need to monitor processes video in order to put advertising banners, and to prevent viewing of up to full view ads. also might want to give access only to authorised or prepay users.

I would like to uslishat neresnytsya, accurate answers to the following question:

1.Is it possible to have a player that is, control hotlinking (for specific websites to allow, it is desirable to configure this from the web interface, even on nginx we are not talking just a backend language need) in PHP ???

2. If not php, then what are the options for solving this problem can offer ?

<?php
/**
 * Description of VideoStream
*
 * @author Rana
 * @link http://codesamplez.com/programming/php-html5-video-streaming-tutorial
*/
class VideoStream
{
 private $path = "";
 private $stream = "";
 private $buffer = 102400;
 private $start = -1;
 private $end = -1;
 private $size = 0;

 function __construct($filePath) 
{
 $this--->path = $filePath;
}

/**
 * Open the stream
*/
 private function open()
{
 if (!($this->stream = fopen($this->path, 'rb'))) {
 die('Could not open stream for reading');
}

}

/**
 * Set proper header to serve the video content
*/
 private function setHeader()
{
ob_get_clean();
 header("Content-Type: video/mp4");
 header("Cache-Control: max-age=2592000, public");
 header("Expires: ".gmdate('D, D M Y H:i:s', time()+2592000) . 'GMT');
 header("Last-Modified: ".gmdate('D, D M Y H:i:s', @filemtime($this->path)) . 'GMT' );
 $this->start = 0;
 $this->size = filesize($this->path);
 $this->end = $this->size - 1;
 header("Accept-Ranges: 0-".$this->end);

 if (isset($_SERVER['HTTP_RANGE'])) {

 $c_start = $this->start;
 $c_end = $this->end;

 list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
 if (strpos($range, ',') !== false) {
 header('HTTP/1.1 416 Requested Range Not Satisfiable');
 header("Content-Range: bytes $this->start-$this->end/$this->size");
exit;
}
 if ($range == '-') {
 $c_start = $this->size - substr($range, 1);
}else{
 $range = explode('-', $range);
 $c_start = $range[0];

 $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $c_end;
}
 $c_end = ($c_end > $this->end) ? $this->end : $c_end;
 if ($c_start > $c_end || $c_start > $this->size - 1 || $c_end >= $this->size) {
 header('HTTP/1.1 416 Requested Range Not Satisfiable');
 header("Content-Range: bytes $this->start-$this->end/$this->size");
exit;
}
 $this->start = $c_start;
 $this->end = $c_end;
 $length = $this->end - $this->start + 1;
 fseek($this->stream, $this->start);
 header('HTTP/1.1 206 Partial Content');
 header("Content-Length: ".$length);
 header("Content-Range: bytes $this->start-$this->end/".$this->size);
}
else
{
 header("Content-Length: ".$this->size);
 } 

}

/**
 * close curretly opened stream
*/
 private function end()
{
fclose($this->stream);
exit;
}

/**
 * perform the streaming of calculated range
*/
 private function stream()
{
 $i = $this->start;
set_time_limit(0);
 while(!feof($this->stream) && $i <= $this->end) {
 $bytesToRead = $this->buffer;
 if(($i+$bytesToRead) > $this->end) {
 $bytesToRead = $this->end - $i + 1;
}
 $data = fread($this->stream, $bytesToRead);
 echo $data;
flush();
 $i += $bytesToRead;
}
}

/**
 * Start streaming video content
*/
 function start()
{
$this->open();
$this->setHeader();
$this->stream();
$this->end();
}
}
July 9th 19 at 10:48
2 answers
July 9th 19 at 10:50
Solution
Actually this here is the line:
if (!($this->stream = fopen($this->path, 'rb'))) {
alluding to the fact that the script opens the file read-only, so problems of concurrent processes with access to this file, as it does not.

The problem may be in the number of simultaneously running php process. 1000 connections = 1000 running processes, each process eats easily 50 megabytes. Memory server enough? :)

All questions of authorization is best left to professionals:
erlyvideo.ru/doc/auth
now that's something to let you know. I thought up to 5 megabytes. Not profitable to rent a server with that amount of RAM.so the Network needs 1,000 megabits. what technology do you recommend for this task ? Performance and Functionality priority (rashitivau on growth projects, and dalneishem do not want to rewrite in another language) - Pansy.Fe commented on July 9th 19 at 10:53
erlyvideo.ru - ask. Be free. Kit to generate a page with the player on anything, and on the server to serve video normal solution. - larue.Tow commented on July 9th 19 at 10:56
erlyvideo.ru/doc/auth - actually everything you need. Then mostly will be in the channel to abut. - larue.Tow commented on July 9th 19 at 10:59
: thank you. but it is necessary to organize the stream files. that's interesting that they use online cinemas which are placed at the server video players with advertising without the ability to rewind. If PHP is so resource expensive. So the other language. Can be Node.js - Pansy.Fe commented on July 9th 19 at 11:02
a lot of options. Simple - keep everything in Vkontakte. Harder - bother the player, which pulls the advertisement, prohibit the wind, the file lies on anything. Right - shift the question of the impact of the content on a normal media server. But the fact in any case - who wants to download - download. - larue.Tow commented on July 9th 19 at 11:05
: this is the online cinema commonplace. just don't want SEO to hire. You can just prohibit the fast forwarding of advertisements and allow you to copy player. I look Node.js is just not a bad decision. Generally PHP + Redis (Sessions) + ajax would solve the problem with a lot of crutches. But the problem with the RAM. And Node.js will be to do everything inside a single process for event-driven model. - Pansy.Fe commented on July 9th 19 at 11:08
: I do not have the concept of working with sockatume. in case an online broadcast of the match.
there is a port that broadcast the match, but the access to that port do not have to give. it is necessary to read from it and give to the port the server socket is written in Node.js is that possible to do ? - Pansy.Fe commented on July 9th 19 at 11:11
What to read about basic concepts: Events, Sockety, Processes. In order to understand such things as Blocking input / output, etc In the books allegedly on the words of languages are all so described as to the programmer C/C++ 10летним experience. - Pansy.Fe commented on July 9th 19 at 11:14
Node.JS inside is still single-threaded. If there are events to process there will be many, not the fact that you will have time to work out. I have already suggested erlyvideo/flussonic. The server is on computer a snap, then he has some API that you can pull the already familiar programming language. - larue.Tow commented on July 9th 19 at 11:17
Basic books - read for cheaters in C/C++, there are more interesting can be described :)) - larue.Tow commented on July 9th 19 at 11:20
: I measured the amount of memory a php script during execution of the method of the stream just inside cycle data before passing the data to the browser (before echo) usage function - memory_get_usage(1) It must return the number of bytes which holds the script. and what happened 262144 bytes. recorded in the text. document. and it is a little more QWERTY MB. - Pansy.Fe commented on July 9th 19 at 11:23
in this case, 16 gigabytes of RAM with a head )) I 8 )) - Pansy.Fe commented on July 9th 19 at 11:26
: this is the memory inside to eat, and the whole process with the kit will be harder. - larue.Tow commented on July 9th 19 at 11:29
: how to measure ? when you run even 10 at a time does not appear the processes of php-cgi processes but more 5мегабайт except Khromov either. (that is not loaded with the cache incognito by opening and php to a txt file writes to confirm that the script was executed) - Pansy.Fe commented on July 9th 19 at 11:32
complete with Apache (even by Windows) has a utility, ab, to run from the command line a bunch of connections and see what really is going on. - larue.Tow commented on July 9th 19 at 11:35
July 9th 19 at 10:52
in PHP to do streaming, it's just a waste of time. Learn python, erlang, at least with nginx+lua
above I said that php expensive for RAM. since for each run of the script runs as a separate process. Python to use to build asynchronous servers ? - Pansy.Fe commented on July 9th 19 at 10:55
you simply select a language for programming in erlang now is the best videostreaming server written in python is more simple in programming - larue.Tow commented on July 9th 19 at 10:58
: learn all about Node.js paired with if ffmpeg will not overload RAM. just under the task. - larue.Tow commented on July 9th 19 at 11:01
: я буду писать хостинг для онлайн кинотеатров. где не более 2000 видео на нескольких машинках с хорошим трафиком. Конечно если бы я собирался писать Кавер Ютуба. мне пришлось бы использовать не только Python и erlang. Но и оптимизировать работу софта используя языки вплоть до C и Assembler. Нанимать не один десяток Senior в разных сферах. Нооо в моем случае думаю по учебничку, мануальчик нужного под задачу скриптового языка с головой )) - Pansy.Fe commented on July 9th 19 at 11:04

Find more questions by tags SocketsVideo broadcastPHPFFmpeg