How I can execute those two command line via php:
wkhtmltopdf www.google.com gg.pdf
&
oofice -headless -nologo -pt cup-pdf my.doc
they both return a pdf file and download into my home directory.
I want to know the way to execute those command from my html page via php.
Thanks.
You should take a look at the System program execution section of the manual : PHP provides several functions that can be used to launch external commands / programs, including :
exec() -- which can store the output of the command in an array
shell_exec() -- which returns, as a string, the output of the command
system() -- which echoes the output of the command
To create a pdf from php(in linux) you must use a wrapper.
$cmd = '/usr/bin/xvfb-run --server-args="-screen 0, 1920x1080x24" /usr/bin/wkhtmltopdf http://google.com /tmp/google.pdf';
exec($cmd);
Related
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?
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.
I have to design a interface using PHP for a software written in python. Currently this software is used from command line by passing input, mostly the input is a text file. There are series of steps and for every step a python script is called. Every step takes a text file as input and an generates an output text file in the folder decided by the user. I am using system() of php but I can't see the output but when I use the same command from command line it generates the output. Example of command :
python /software/qiime-1.4.0-release/bin/check_id_map.py -m /home/qiime/sample/Fasting_Map.txt -o /home/qiime/sample/mapping_output -v
try this
$script = 'software/qiime-1.4.0-release/bin/check_id_map.py -m /home/qiime/sample/Fasting_Map.txt -o /home/qiime/sample/mapping_output -v';
$a = exec($script);
If you are not on windows, have you tried adding 2>&1 (redirect stderr to stdout) to the end of the command?
$output = system("python /software/qiime-1.4.0-release/bin/check_id_map.py -m /home/qiime/sample/Fasting_Map.txt -o /home/qiime/sample/mapping_output -v 2>&1", $exitcode);
Found from http://www.php.net/manual/en/function.system.php#108713
Also the doc says that it
Returns the last line of the command output on success, and FALSE on
failure.
So if you are trying to get multiple lines, you may need to redirect it to a file and read that in.
instead of system() try surrounding the code in `ticks`...
It has a similar functionality but behaves a little differently in the way it returns the output..
how can I execute command wkhtmltopdf http://google.com /tmp/test.pdf from server ie http://localhost/test.php, when I do it from command line it works. I tried system() and exec() functions but did not work. When I use system('touch /tmp/test') file is created. What stops wkhtmltopdf? Is it php, apache?
Make sure that the user the script is running as knows where wkhtmltopdf bin is.
You can find out where it is with the which command.
which wkhtmltopdf
Also you can get the return status of a command by setting a variable equal to it
e.g.
$last_line = system('ls');
echo $last_line
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/