E
E
Emil2021-11-11 17:34:29
PHP
Emil, 2021-11-11 17:34:29

Why can't Monolog write the file?

I'm trying to run HLS stream via FFMpeg.
I use the library https://github.com/aminyazdanpanah/PHP-FFmpeg-vide... .
The code:

require '/phplibs/vendor/autoload.php'; // path to the autoload file
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$config = [
    'ffmpeg.binaries'  => '/usr/bin/ffmpeg',
    'ffprobe.binaries' => '/usr/bin/ffprobe',
    'timeout'          => 3600, // The timeout for the underlying process
    'ffmpeg.threads'   => 12,   // The number of threads that FFmpeg should use
];

$log = new Logger('FFmpeg_Streaming');
$log->pushHandler(new StreamHandler('/var/log/ffmpeg-streaming.log')); // path to log file
    
$ffmpeg = Streaming\FFMpeg::create($config, $log);
$video = $ffmpeg->open('video.mp4');
$video->hls()
    ->x264()
    ->autoGenerateRepresentations([1080, 480, 240])
    ->save('hls-stream.m3u8');

Mistake:
[Thu Nov 11 17:20:48.713222 2021] [proxy_fcgi:error] [pid 10223] [client IP:52534] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Streaming\\Exception\\RuntimeException: Unable to save the file in /phplibs/vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/File.php:68\nStack trace:\n#0 /phplibs/vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/HLSPlaylist.php(92): Streaming\\File::put()\n#1 /phplibs/vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/HLS.php(314): Streaming\\HLSPlaylist->save()\n#2 /phplibs/vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/HLS.php(303): Streaming\\HLS->savePlaylist()\n#3 /phplibs/vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/Stream.php(123): Streaming\\HLS->getPath()\n#4 /phplibs/vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/Stream.php(163): Streaming\\Stream->run()\n#5 /var/www/html/test-hls/hls.php(21): Streaming\\Stream->save()\n#6 {main}\n  thrown in /phplibs/vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/File.php on line 68'

I don't fully understand what the server is trying to tell me.
Before this was a mistake
[Thu Nov 11 17:19:17.884360 2021] [proxy_fcgi:error] [pid 10221] [client IP:52527] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/var/log/ffmpeg-streaming.log" could not be opened in append mode: failed to open stream: Permission denied in /phplibs/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:146\nStack trace:\n#0 /phplibs/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(48): Monolog\\Handler\\StreamHandler->write()\n#1 /phplibs/vendor/monolog/monolog/src/Monolog/Logger.php(327): Monolog\\Handler\\AbstractProcessingHandler->handle()\n#2 /phplibs/vendor/monolog/monolog/src/Monolog/Logger.php(526): Monolog\\Logger->addRecord()\n#3 /phplibs/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(60): Monolog\\Logger->info()\n#4 /phplibs/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(207): Alchemy\\BinaryDriver\\ProcessRunner->run()\n#5 /phplibs/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(136): Alchemy\\BinaryDriver\\AbstractBinary->run()\n#6 /phplibs/...'
Permission Denied, created a file in the specified location, set the rights to 777.
Now I only write "Unable to save the file in", I would like to ask. And what exactly does this mean? He can't create the file? Save it? Overwrite? No rights?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ipatiev, 2021-11-11
@Fockker

It's all in the error messages.
The monologue cursed that he did not have enough rights to record. And I swore rightly, because writing application logs to /var/log is a very so-so idea.
And this amyazdanpapanah herself does not swear at anything, because its author is a moron.
For this

if (false === @file_put_contents($path, $content)) {

I want to hit my fingers with something heavy for a very long time.
so that never again in my head even the thought would arise to write such highly intelligent code.
which, just does what hides the real cause of the error
Which, most likely, again "no rights." Only not for logs, but for the actual file being created.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question