kilian how i can run this script in background when you upload content on files and upload finish? will be perfect, for run the script only when its needed.
I can't give you a perfect answer on how to execute the script without blocking, as I would have to do some testing myself. Essentially, you would add it to index.php
around line 1398
find this:
// all is well! attempt to move_uploaded_file()
if(@move_uploaded_file($file['tmp_name'], "$path/$filename")) fm_json_exit(true, array(
'success' => true,
'filename' => $filename, // return filename in case it was incremented or renamed
'url' => get_url_path("$path/$filename") // for usage with showLinkToFileUploadResult
));
Assuming you have the bash script stored as something like script.sh
, you could do something like:
// all is well! attempt to move_uploaded_file()
if(@move_uploaded_file($file['tmp_name'], "$path/$filename")) {
shell_exec('./script.sh > /dev/null 2>/dev/null &'); // run the task!
fm_json_exit(true, array(
'success' => true,
'filename' => $filename, // return filename in case it was incremented or renamed
'url' => get_url_path("$path/$filename") // for usage with showLinkToFileUploadResult
));
}
According to the post on stackoverflow, > /dev/null 2>/dev/null &
should allow the script to run in the background without blocking the PHP response to Files Gallery. Also, you may need to modify the path to ./script.sh
and also forward the $path
as a parameter so that the script knows what dir to process. If all goes well, the script would run and only process files that need to be converted or watermarked.
kilian (i can do it but editing index.php and i want keep updating this script)
For now, there is no solution to this. If you get it working, it's a fairly simple modification to the code, that would have to be applied after each update, which won't be too frequent.
kilian also i have a permissions problem, when you encode a video with ffmpeg i cant edit or remove the video file, dont have permissions.
It's likely you have a WWW-user (PHP) that owns uploaded files, and perhaps a root-user (or another user) for FFmpeg, which creates the converted/watermarked files. The www-user then doesn't have permissions to modify the files owned by another user. This is all part of your system users and permissions. Best solution would be to avoid having multiple "users" (eg. different users for ffmpeg and www), but it could also be resolved by running chmod (change permissions to make files writeable for other user) or chown (change ownership of the created file) after FFmpeg creates files.