Reading files through php

You all know about the limitations that exist in the general environment, so with that in mind, please offer me a php function or something else with which I could transfer my videos and other files. I have a lot of videos on the server, unlimited bandwidth and disk space, but I am limited in ram and cpu.

+4
source share
3 answers

Do not use php to stream data. Use the header redirection to specify the URL of the actual file. This will disable the work on the web server, which can work under a different user ID and is better optimized for this task.

+2
source

Hmm, there is XMoov that acts like a "streaming server", but not much more than serving the file byte as a byte, with a few additional parameters and settings. These promises random access (i.e. random skipping inside the video), but I haven't used it myself yet.

As a server administrator, however, I would frown at anyone who uses PHP to serve such huge files due to the load that he puts on the server. I would not consider this a good idea at all and instead rented a streaming server, if at all possible. Use at your own risk.

0
source

You can use the while loop to load the bits of the file, and then sleep for a while, and then output more and sleep ... (this is the only way to limit CPU usage).

RAM should not be a problem, since you are simply unloading parts of the file, so you do not need to load them into RAM.

0
source

Source: https://habr.com/ru/post/1308651/


All Articles