[英]php execute shell commands, dyld: Library not loaded: /usr/lib/libxml2.2.dylib
I am trying to use wkhtmltopdf executable to convert some html to pdf. 我正在尝试使用wkhtmltopdf可执行文件将一些html转换为pdf。 I'm just testing it out on my mac and if I run the executable via terminal it works fine. 我只是在Mac上测试它,如果我通过终端运行可执行文件,它就可以正常工作。 If I run it using php shell_exec I get the following error: 如果我使用php shell_exec运行它,则会出现以下错误:
dyld: Library not loaded: /usr/lib/libxml2.2.dylib Referenced from: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices Reason: Incompatible library version: DictionaryServices requires version 10.0.0 or later, but libxml2.2.dylib provides version 9.0.0 dyld:未加载库:/usr/lib/libxml2.2.dylib引用自:/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices原因:库版本不兼容:DictionaryServices需要版本10.0.0或更高版本,但libxml2.2.dylib提供版本9.0.0
If I spit out the cmd that I'm using via php I can run it and it works fine in the terminal. 如果我通过php吐出正在使用的cmd,则可以运行它,并且在终端中可以正常工作。
I think it's a pathing issue, so I echoed out my users path which was different than the paths avialble to php, so I added it to the command before: 我认为这是一个路径问题,因此我回显了我的用户路径,该路径与php可用路径不同,因此我在之前将其添加到命令中:
PATH=$PATH:/usr/local/sbin:/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php5/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/opt/subversion/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin; ./wkhtmltopdf-0.9.9-OS-X.i368 ./'newxhtml.html' /tmp_pdf.pdf
Any thoughts on what I might be doing wrong? 对我可能做错的事情有任何想法吗?
Thanks, MS 谢谢,女士
Figured out what was going on. 弄清楚发生了什么事。
First to trouble shoot I ran the command: 首先解决问题,我运行了命令:
env 环保
From both my terminal and my php secript. 从我的终端和我的php脚本。
I noticed in my php script that it had the following explicitly set: 我在我的PHP脚本中注意到它具有以下明确设置的内容:
DYLD_LIBRARY_PATH=/some/path DYLD_LIBRARY_PATH = /一些/路径
But in the terminal that value wasn't set at all. 但是在终端中,这个值根本没有设置。 So all I did was add: 所以我所做的就是添加:
DYLD_LIBRARY_PATH=""; DYLD_LIBRARY_PATH =“”;
Here's my final command: DYLD_LIBRARY_PATH="";./wkhtmltopdf-0.9.9-OS-X.i368 ./'newxhtml.html' ./tmp_pdf.pdf 2>&1 这是我的最终命令:DYLD_LIBRARY_PATH =“”; ./ wkhtmltopdf-0.9.9-OS-X.i368 ./'newxhtml.html'./tmp_pdf.pdf 2>&1
And I just run it via shell_exec. 我只是通过shell_exec运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.