V
V
vadim64462021-10-07 09:55:12
PHP
vadim6446, 2021-10-07 09:55:12

Why does the site freeze when I launch an external program?

Good afternoon! There is a small site (running on an nginx server) that generates video using ffmpeg and gives it to the client for download.
The code:

header('Content-type: video/mp4');

$cmd = "ffmpeg -i file.mp4..."
$process = proc_open($cmd, $descriptorspec, $pipes, getcwd());
 if (is_resource($process)) {
    while(!feof($pipes[1])){
        $chunk = fread($pipes[1], 500*1024);
        $stdout_size += strlen($chunk);
        if ($chunk !== false && !empty($chunk)){
            echo $chunk;
            if (ob_get_length()){            
                @ob_flush();
                @flush();
                @ob_end_flush();
            }
        }
    }
}


The whole thing works, but there is a minus, it lies in the fact that when 1 of the clients downloads the video, the site is unavailable (perpetual loading in the browser). As soon as the client finishes downloading the video, the site becomes available again. Tell me, please, what could be the reason? And how can this problem be solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-10-07
@karabanov

Add workers in php-fpm pool config
You can also try updating php-fpm...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question