I want to send ffmpeg output to a php file so I can use a regex and update the output into a database. This will allow me to handle progress for multiple uploads. Does anyone know how to do this? Can it be done? Currently I can execute a php file with parameters after the ffmpeg command, and get ffmpeg to write to a txt file but can I send the output to the php file and execute it?
execute php file with parameters
&& php /opt/lampp/htdocs/xampp/site/update_db.php ".$parameter1." ".$parameter2.";
Write output to txt file
ffmpeg command and filepath to converted 1> /home/g/Desktop/output.txt 2>&1
Can something like this be done?
ffmpeg command and filepath to converted 1> php /opt/lampp/htdocs/xampp/site/update_db.php ".$output." 2>&1
Yes, you can read STDIN.
http://php.net/manual/en/features.commandline.io-streams.php
If it were me, I'd just execute FFMPEG from within PHP. You have a bit more flexibility that way, but I know that isn't desirable for every application.
You could use exec to call ffmpeg, then use the content of the output parameter to get returned output.
But doing so only allow you to get the output once the program execution is terminated:
If a program is started with this
function, in order for it to continue
running in the background, the output
of the program must be redirected to a
file or another output stream. Failing
to do so will cause PHP to hang until
the execution of the program ends.
Related
I'm trying to write a cronjob which launches multiple processes that I want to run in parallel.
I'm using a foreach calling each command, but the command line waits for the output. I don't want it to put.
Was wondering if anyone ever used any library for this?
Add an ampersand after the command:
$ php task.php &
It will run that instance of php in the background and continue.
If you read the manual on passthru you'll notice it tells you how to avoid this...
If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
So you can rely on UNIX fds to redirect output to something like /dev/null for example if you don't care about the output or to some file if you do want to save the output and this will avoid PHP waiting on the command to finish.
pssthru("somecommand > /some/path/to/file")
When I run the command node auth.js in my cmd tool,I get the output..I want to get the output of javascript in php file.So I tried below codes but its returning empty output
<?php
exec("node auth.js &", $output);
var_dump($output);
?>
I also tried full path.But still not working.And is it safe to use the above codes ? or is there any php class wrapper to do this job.
I seems you are telling to the shell to send in background the executable (node and its file), so the standard output will be redirect on the new forked shell instead of the one you are waiting for in your php code.
If you want to leave the program executing in background, you can redirect output to a file and then read it inside php.
Hope it was useful to you :)
I currently use nohup to run a long php script and redirect the live results to a file using this command
nohup php long_file.php >logs 2>&1 &
so i just go and visit logs file continuously to see the results
Now i want to do the exact same thing using another php file to execute the above command
i tried the above command with php exec and the redirect output doesn't seem to be working,
I know i can just retrive the output using php and store it using any file write function but the thing is .. the output is too long thats why i keep it running on server's background
a similar question :
Shell_exec php with nohup, but it had no answer
any solution ?
Please try with -q
nohup php -q long_file.php >logs 2>&1 &
http://ubuntuforums.org/showthread.php?t=977332
Did you try passthru instead of exec?
You are redirecting STDOUT to a file by using >
This will truncate the file each time the script is run. If two scripts simultaneously redirect their output to the same file, the one started last will truncate the output from the first script.
If you really want to properly append to a log file with multiple concurrent running scripts, consider using >> to avoid having the log file truncated.
Side effect however is that the log file never truncates and keeps expanding, so if the file gets really large you can consider including it in a logrotate scheme.
I'd like to be able to stop FFMPEG from PHP (on Windows).
What I'm doing now is starting it as so:
pclose(popen("start ffmpeg -i rtmp://livestream -o a_file.mp4", "r"));
But as soon as I've done that I've lost all connection to the program (right?).
I would like to send a 'q' to the process to stop it. Is there any way to do this?
EDIT: I should probably explain that I use pclose because I need the PHP script to keep running and thus close the file pointer. Maybe the question should be: How can I keep the script running and the file pointer open?
proc_open gives you a file pointer so you can then write to the input of the program. There are examples on the doc page.
I have a PHP script that executes a .bat file using
system("cmd /c C:\dir\file.bat");
This launches an AWS server and returns info such as the id of the server started. I need to use this id in the script later on. How can I return the results from the .bat file to PHP and then how can I extract the id from the rest of the results. Is the returned data simply a string that i need to slice to get the bit i need?
I will then run a .bat file that executes the following -
ec2-associate-address -i i-######id ip.###.###.###
Thanks all
You can capture the output of a system command by using the exec() function or passthru() function.
Instead of system() you can use proc_open(). That way you can read the output of your .bat file by reading the stdout pipe. You then get your simple string that you can slice 'n dice to get your process ID.