【问题标题】:Calling git command from PHP script returns "dyld: lazy symbol binding failed"从 PHP 脚本调用 git 命令返回“dyld:惰性符号绑定失败”
【发布时间】:2014-11-24 16:35:04
【问题描述】:

我在 Mac OSx 上,使用 MAMP。当我直接在终端中运行 git 命令时,它们按预期工作,没有错误。但是我正在用 php 编写一个脚本,该脚本旨在运行一些 git 命令,并且出现以下错误:

exec('cd /my/path/here/ 2>&1 && git init 2>&1', $out, $return);

返回:

Array ( [0] => dyld: lazy symbol binding failed: Symbol not found: _iconv_open [1] => Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/git [2] => Expected in: /Applications/MAMP/Library/lib/libiconv.2.dylib [3] => [4] => dyld: Symbol not found: _iconv_open [5] => Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/git [6] => Expected in: /Applications/MAMP/Library/lib/libiconv.2.dylib [7] => )

搜索会给出一堆结果(例如here),说明这是一个 OSx / MAMP 问题,解决方法是将export DYLD_LIBRARY_PATH=/usr/lib/ 添加到您的.bash_profile。但正如我所说,我从终端没有问题,我只在从 php 的exec() 调用 git 时得到错误。我确实将DYLD_LIBRARY_PATH=... 添加到我的bash_profile 中,但没有任何区别。

调用exec() 不会调用我的bash_profile,即使Apache 设置为我的普通用户运行?

【问题讨论】:

    标签: php git exec mamp dyld


    【解决方案1】:

    如果这可行,那么我认为 exec 没有调用您的 bash_profile。

    exec('export DYLD_LIBRARY_PATH=/usr/lib cd /my/path/here/ 2>&1 && git init 2>&1', $out, $return);
    

    【讨论】:

    • 这确实有效,我在发布之前实际上已经尝试过了。但我正在编写的脚本将被推送到我团队的版本控制中,并分发给其他开发人员。我不认为我可以将“非便携式”硬编码到脚本中。
    • 你可能被这个stackoverflow.com/questions/3428647/…欺骗了
    • 感谢您的链接。如果我运行echo shell_exec("echo $0");,我会得到sh,而不是bash。所以似乎 PHP 甚至没有调用 bash。我想我的问题变成了如何让 php 在运行 shell 命令时使用 bash,或我如何让 bourne shell 更改其 DYLD_LIBRARY_PATH?
    猜你喜欢
    • 2013-03-18
    • 2013-10-27
    • 2014-01-01
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多