开发者

shell_exec() in PHP doesn't execute my specific command

I'm currently building a class in PHP that generates PDF documents using the WKHTMLTOPDF command line app.

To do this, I'm using a call to shell_exec to call the WKHTMLTOPDF executable. However, this particular call does not seem to be executed; it returns NULL almost instantly.

A small test I did gave me the following results:

var_dump(shell_exec('ping nu.nl'));
// This prints a string, containting the expected output of the ping command
var_dump(shell_exec('"c:/wkhtmltopdf/wkhtmltopdf.exe" --orientation "Landscape" --page-size "A2" --margin-top "25mm" --margin-left "20mm" --margin-bottom "20mm" --margin-right "20mm" "http://www.nu.nl/" "C:/Temp/1280310218.pdf"'));
// This prints NULL

So, shell_exec() seems to be working, also safe_mode is off, and pasting the full command into cmd.exe does run the command properly.

If the problem isn't in either of the above (safe mode, a faulty command, or shell_exec() itself) what else can it be? All I can think about is a user rights issue, but both the execu开发者_运维问答table and the directory it's in have full access settings for every user group on my system.

(Note: Though I'm developing on a Windows machine, this code will run on a Linux server in production. Hence, windows-only solutions aren't what I'm looking for, unless ofcourse this problem itself turns out to be related to windows)


Check permissions by create file using fopen() in temp dir. Does it create pdf ? Maybe this program doesn't output to stdout, but stderr same as ffmpeg for example. Try adding "2>&1" after your command.

Or, this software uses some files in directory where is installed. Try first to change directory by adding something like "cd c:\wkhtmltopdf;YOUR_COMMAND"


You could use a php library to do that, which would be more efficient and integrated. There is for example html2pdf.


remove these environment variable settings >>

"DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"

#export DYLD_LIBRARY_PATH

and it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜