know when ffmpeg completes converting - php

am using ffmpeg in one of my sites with PHP , i convert files using the php exec function , actually it did me some headache trying to figure out WHEN this ffmpeg completes the file conversion after executing the exec command :( is there anyway to do that ?
Thanks

From what I've found, the exec function blocks until the ffmpeg conversion is complete.
For example, you can run ffmpeg like this in your PHP script:
exec($encode, $output);
(Where $encode is the ffmpeg command as a string, and $output is an array of each line of output from ffmpeg.)
For me, this exec command blocks my PHP script from continuing until ffmpeg conversion is complete, at which point my PHP script continues on, which seems to be how it is described in the PHP manual:
http://php.net/manual/en/function.exec.php
So, you can tell when exec is complete by following the exec command with another PHP command on the next line in your script that notifies you conversion is complete, or updates a database, or what-have-you.
FYI, I believe that pushing the exec command "into the background" means running the exec command but having the PHP script continue on simultaneously (i.e. asynchronously). For running the exec command in the background, Google "PHP background exec" or "php multi-process", such as:
http://www.php.net/manual/en/ref.exec.php#80241
http://www.sitecrafting.com/blog/to-run-php-code-in/

Related

Pageres using PHP exec

I'm using Pageres to capture a Highcharts chart. I have a PHP script that takes in an argument to generate the proper URL and file name for the pageres command. When I go to use PHP's exec command, it fires off a bunch of pageres commands and never actually completes the pageres command. The pageres command works perfectly from the command line though.
Snippet of my PHP code:
$cmd = "pageres http://localurl/wriphp/visGraph.php?port=".$port." 1100x200 --filename ".$port;
exec($cmd);
Why does the php exec call run out of control?

Execute powershell command via php

I have the following problem:
I hava a xampp sever running and I want it to execute a powershell. A php triggers a .bat file which contains the following code:
#echo
cd C:\OpenBR\bin
start /WAIT br -algorithm FaceRecognition -compare C:\xampp\htdocs\upload C:\xampp\htdocs\DP C:\xampp\htdocs\results\result.csv
start /WAIT C:\xampp\htdocs\CSVconvert\sortieren.ps1
start /WAIT C:\xampp\htdocs\CSVconvert\Removedouble.ps1
start /WAIT C:\xampp\htdocs\CSVconvert\remove_path.ps1
start /WAIT C:\xampp\htdocs\CSVconvert\remove_foo.ps1
start C:\xampp\htdocs\CSVconvert\remove_quoatation.ps1
The first part works fine, up until the point when i want to exec the powershell "sortieren.ps1". When I run the batch manually, it executes and does the job, when triggered via php, it doesn't.
I set "Set-ExecutionPolicy Unrestricted" in both x86 and x64 shells.
I am just confused because the normal command line works and powershell doesn't, even after setting it on unrestricted.
I viewed
executing a Powershell script from php
and
PowerShell on Windows 7: Set-ExecutionPolicy for regular users
but couldn't solve the problem.
What did i miss?
The session you are running those commands in doesn't have the same environment variables as when you are using PowerShell to run them manually. You'll have to specify the absolute path to the powershell executeable and the scripts that you want to run so that they will be found.
start /WAIT C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\xampp\htdocs\CSVconvert\sortieren.ps1
Since the problem was the environment i thought you might benefit from a package that handles that aspect automatically. Here is a project that allows PHP to obtain and interact dynamically with a real Powershell. Get it here: https://github.com/merlinthemagic/MTS
After downloading you would simply use the following code:
$shellObj = \MTS\Factories::getDevices()->getLocalHost()->getShell('powershell');
$strCmd1 = 'first command from first script';
$return1 = $shellObj->exeCmd($strCmd1);
$strCmd2 = 'second command from first script';
$return2 = $shellObj->exeCmd($strCmd2);
Instead of triggering a single script you can just trigger each command individually and handle the return. You can issue any command you like against the $shellObj, the environment is maintained throughout the life of the PHP script.

How to run 2 dependent shell commands by php

i have 2 shell commands and i want to exec in php the first command that act like an application and stay into it and exec another command there (in this application).
i write in my shell: wpa_cli
and get the result:
Interactive mode
>
now i can write commands in that software, like:
Interactive mode
> status
and get the result:
wpa_state=DISCONNECTED
p2p_device_address=34:b1:f7:1f:2d:bb
address=34:b1:f7:1f:2d:bb
>
my problem is that i want to do that outside the shell by php.
how can i do that?
Your requirement is similar to this interactive shell using PHP, but it requires execution of PHP script in terminal, which you don't want.
So, in this case, you can use any of these php functions: shell_exec, exec, system or passthru and run both wpa_cli status commands together, you will get the required result.
e.g. run the following script in your php file and see the output,
echo '<pre>'. shell_exec('wpa_cli status') .'</pre>';
You can also use PHP Ajax Shell or similar scripts to execute your commands and get response on the same page without reloading it.

Using the `where` command through PHP

I am trying to get the path to certain exe's using the where command in the command prompt on windows.
Here is what i did in command prompt.
where g++
where java
where javac
where python
All of these are giving the correct output of the path in the console window which indicated that I have set the environment variables correctly.
But now When i try to run the commands using the shell_exec() function in PHP, only the call to where java and where python gives the correct output. I was even able to successfully execute a respective test file using these commands through PHP.
But strangely, where g++ and where javac give this error in the browser when run through PHP:
INFO: Could not find files for the given pattern(s).
Also if I get the outputs of these two commands on the console and then copy that into my script to compile a c++ or java file, it works perfect. But the where command returns the above INFO when run through the PHP script.
I am running the server on localhost using XAMPP. Any idea what is missing?

Running a Python script in the background from a PHP file

I need to run a Python script in the background after being called from a PHP file. The PHP file should continue to run independently of the Python script (i.e. it shouldn't hang waiting for the Python script to finish processing, but should instead carry on processing itself).
The Python script takes one argument and produces no output (it merely processes some data in the background), then exits. I'm running Python 2.6, PHP 5.2.6, and Ubuntu 9.04.
You could use exec() to kick off the Python interperator and have it send its output to either a file or to /dev/null with redirection. Using the & operator in the exec call will cause the command to be started and PHP to continue without waiting for a result.
http://www.developertutorials.com/tutorials/php/running-background-processes-in-php-349/ goes into more detail.
PHP Process Control can be used for this. The proc_open command can be used to start a process. You can later check up on it, read it's output etc.
View the manual entry: http://www.php.net/manual/en/function.proc-open.php and search around google for PHP Process Control
I'm guessing the PHP file is called via Apache, in which case you won't be able to fork(). You should make your Python script daemonize. Check out python-daemon.
You could use:
<?php
shell_exec('./test.sh &');
?>
where ./test.sh should be the execution line to your script

Categories