I'm trying to check before running a php script if pdftohtml is installed on server.
Is there a way to check if pdftohtml is installed on server (linux or mac) from within the code.
I'm looking for something similar to function_exists()
Perhaps, the following will solve your case:
$isInstalled = (bool) shell_exec('which pdftohtml');
which returns nothing if the program isn't found. But it will only work if it's installed globally (without specifying an absolute path). And returns a full path if it's there
Related
I have a very strange problem.
I'm trying to make a program that executes shell_exec() in PHP with NMAP.
The problem comes when I put shell_exec("nmap --version"), because it returns me version 4.11, but when I put it directly on shell, it returns me version 7.01.
When using shell_exec you should always use the full path to the executable.
I built a pdf generator script for one of my clients and everything works properly. He then decided that he wanted me to create a thumbnail image from the PDF to display on another page, so I came across PHMagick and that seemed to do the trick.
The following code worked on my building server (iPage -- I think it's debian?), but now that I've moved it to his VPS, it is no longer working. FPDF has no trouble generating the pdf, so it is not a permissions issue.
Code:
require("phmagick/phmagick.php");
$pdf->Output("pdf.pdf");
$p = new phmagick('','pdf.png');
$p->debug = true;
$p->resize(800);
$p->acquireFrame("pdf.pdf");
This code returns the following error:
Error executing "convert "pdf.pdf"[0] "pdf.png"" return code: 127 command output :"sh: convert: command not found"
I have not changed any of the code since I moved it from the original server, and I just copied the entire site over, so why is PHMagick not working now? How do I get it to recognize convert.php in the plugins folder?
Just a note: I am only using PHMagick, not the whole of ImageMagick.
PHMagic appears to be using the command line convert command in background.
Most likely that command is simply not installed on the server.
PHMagic use the command line convert,composite etc... commands in background.
These commands are only available if ImageMagick is installed in your server.
In your previous server ImageMagick must have been installed.
Ipage sometimes do not pre install ImageMagick on their VPS servers. And you might not be able to install it your self ( through terminal login using ... yum install ImageMagick ) coz you will be prompt for root password.
To make sure the ImageMagick binaries are installed in ur server, in ur case the convert command,
type this command in the ssh terminal...
whereis convert
If the path to the convert command is not shown, it means you need to install ImageMagick.
You will have to open a support ticket and ask them to install it for you
As arkascha said, you'll need to install imagemagick. Try yum install imagemagick since you're running CentOS.
EDIT: May be a different capitalization: ImageMagick
i installed the xhprof profiling extension for php
Everything is fine except for the callgraph.php file, it returns:
failed to shell execute cmd=" dot -Tpng"
so i checked and the dot utility wasn't installed, so i installed it.
it appears to be running fine from the command line so i ran the scritp again, same error:
failed to shell execute cmd=" dot -Tpng"
the xhprof documentation states:
the callgraph image visualization ([View Callgraph]) feature relies on the presence of Graphviz "dot" utility in your path.
but i don't understand what i need to do now, specifically the "utility in your path" part
Any help appreciated, thanks guys
If you want graphing functions for xhprof run next command in terminal:
sudo apt-get install graphviz
When I enable error_reporting, I see there are some configuration variable are missing:
function xhprof_generate_image_by_dot($dot_script, $type) {
// get config => yep really dirty - but unobstrusive
global $_xhprof;
$errorFile = $_xhprof['dot_errfile'];
$tmpDirectory = $_xhprof['dot_tempdir'];
$dotBinary = $_xhprof['dot_binary'];
After add the following lines to xhprof_lib/config.php, it works
$_xhprof['dot_errfile'] = '/home/peniel/var/log/xhprof/error.log';
$_xhprof['dot_tempdir'] = '/home/peniel/var/log/xhprof';
$_xhprof['dot_binary'] = '/usr/bin/dot';
If you have installed graphviz this error also will occure because of the security restrictions. Some functions may be disabled. So, see your logs for some php warnings.
For example:
PHP Warning: proc_open() has been disabled for security reasons in /usr/share/php/xhprof_lib/utils/callgraph_utils.php on line 112
You need to configure php.ini or security.ini parameter "disable_functions".
Having the utility "in your path" means that it can be located by the environment variable PATH. This environment variables contains directories where the shell looks for binaries that you run without an explicit path.
Let's say the full path to dot is /opt/foo/bin/dot. Then you want to modify your PATH environment variable this way:
PATH=${PATH}:/opt/foo/bin
In my case this was caused simply because graphviz was not installed. You can check with which dot or locate graphviz on the command line.
steps for fast fix the issue if you have Graphviz and still getting error:
run "which dot"
/usr/local/bin/dot
open xhprof_lib/utils/callgraph_utils.php line 110
replace "dot" by "/usr/local/bin/dot" (or path you have)
How can I receive the Zend Server version by a PHP script running on this Zend Server?
phpinfo() and the commandline php -v does not tell the Zend Server version!
You cannot derive the Server version from phpinfo (or the environment for that matter).
I assume you are after the values that are displayed in the Server Control GUI at Monitor | Server Info, e.g. version and build. They are stored in in $InstallDir/GUI/application/data/zend-server.ini. Your application has to have access to the folder where the Ini is located, load the Ini file (with something like Zend_Config) and then you can work with the values.
Note that ZS is build with ZF and the files are not obfuscated, so you can check out their source code to see how they access this information. Might very well be possible to reuse some of their code.
A quick and dirty way to get it:
$ cat /usr/local/zend/gui/application/data/zend-server.ini | grep version
Here you would replace /usr/local/zend with whatever alternative path you might have chosen.
And you'll get some output like:
version = 5.6.0
You can use the following command:
echo Zend_Version::VERSION;
Open the zend server .ini file (zs_ui.ini) and find version.
...\Zend\ZendServer\gui\config\zs_ui.ini
Example:
zend_gui.version = 9.0.1
I have an own webserver and for one of my clients I need to be able to search through PDF's. I've asked my hostingprovider to install the xPDF package. Now I've come to testing and I'm calling this line of code in a PHP script:
$content = shell_exec('/usr/local/bin/pdftotext test.pdf -');
The only thing is, I'm getting a NULL result with. So, my question, is there a way to validate if the program is really installed? Btw, I'm not even sure if the path is correct. I'm pretty new if it comes to having an own webserver. I've taken this example from : http://davidwalsh.name/read-pdf-doc-file-php
If you have shell access, log in using SSH, and try
whereis pdftotext
if the only thing you get is a
pdftotext:
then it is most likely not (or not properly) installed.