PDA

Click to See Complete Forum and Search --> : [RESOLVED] PHP Exec Not running, but command works ok!


Pino
Sep 6th, 2010, 10:24 AM
I have the following script to take an uploaded PDF in PHP and call ImageMagik/Ghostscript to convert to images of specified size.

$tmp = exec("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"", $results);

However, this doesnt seem to work. No errors in the log file and no errors on screen. If I do the following,

$tmp = exec("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"", $results);
echo ("convert \"{$strPDF}\" -resize 500X500 \"{$strOut}\"");

And I paste the output into a command prompt it works fine (It takes around 6-10 seconds - My max_execution_time is at 600.

Any suggestions on why this might not be working?

This is Windows, IIS 7 and PHP5.

Edit: I'm having the same issue in both CentOS and Windows. Both have ImageMagik and Ghostscript installed.

kows
Sep 6th, 2010, 12:10 PM
can you make sure that the user running IIS (or Apache on CentOS) has the authority to execute those commands?

Pino
Sep 6th, 2010, 12:38 PM
can you make sure that the user running IIS (or Apache on CentOS) has the authority to execute those commands?

Ok I'm not amazing with linux stuff, can you run through how I would go about doing that in CentOs?

penagate
Sep 6th, 2010, 07:28 PM
Use the stat command on the input file and/or the directory where the output file will be written.
Look at the owner setting and the permissions set.
You can use exec('whoami') to find out what user your script is running as.

Also, try trapping the return code from the exec command. Pass a variable into the third parameter and then read that after exec returns.

Pino
Sep 7th, 2010, 02:01 PM
Still cant resolve this, the third param comes back as "1". Is there anything else I can do to Debug this?

kows
Sep 7th, 2010, 10:47 PM
this (http://ca2.php.net/manual/en/function.exec.php#86444) comment seems helpful for running exec() on Windows, but I'm not sure of the problem for your CentOS install.

the last time I had issues using exec(), I was trying to auto-extract RAR archives using WinRAR. I ended up fixing it, but I'll see if I can't reproduce the problem and give you a solution for at least the Windows side of things. I do have a server running CentOS, so I could look for and see if I run into the problem with ImageMagik or WinRAR on that machine, and let you know what I run into. I can't promise this will be tonight, though!

kows
Sep 12th, 2010, 06:13 PM
Hi.

I took my time getting back to you! Anyway, I didn't realize ImageMagick was installed on most Unix systems already, so I ran the following to test via the console:

convert logo.png -resize 120x60 small.png

and it worked fine. Then, I ran the following using PHP 5.3.3 on Apache 2.2.16:

<?php

exec("convert logo.png -resize 60x30 small.png");

?>

My guess would still be user permissions, I suppose. I'm using a web hosting account with WebFaction, where I don't have a caged shell (whereas most web hosts do limit what you can do via SSH). I also ran the script above using WebFaction's shared install of Apache/PHP5.2 after I had success with my custom install of Apache/PHP5.3, and the results were the same. The directory that the script was running from was chmodded to 755.

Pino
Sep 13th, 2010, 04:25 AM
Yea it was a permissions issue, but not somthing that I can work out how I fixed. I have it working well on the CentOS box but windows is still failing. Not a big issue though as CentOS was the main one.

Thanks for the help.