从 PHP 调用 Mono
这有点复杂。 :-) 我有一个用 PHP 编写的网站,需要调用用 .NET 编写、在 Mono 下运行的外部程序。它像往常一样调用程序:(
/path/mono /path/executable arguments...
我也尝试将其放入 bash 脚本并从 PHP 调用脚本本身)。
据我所知,一切都按要求设置。 Mono本身运行没问题,可执行文件(或脚本)具有可执行权限,所有者也没有问题。正确的设置也可以从以下事实确定:如果我从服务器(Debian Lenny)上的命令行发出上面的命令行(或调用提到的脚本),一切都会完美运行,我的可执行文件执行时不会出现错误。
但是,如果 PHP 调用相同的方法(使用 exec()、system() 或任何其他变体),我会立即从 Mono 获得退出代码 6,并且我的可执行文件根本不会运行(为了测试它,我使用“Hello World”可执行文件不执行任何操作,只是发出单个输出行并返回 0)。编译时没有任何额外的依赖,只是一个真正的“Hello Word”。绝对可以肯定这个程序不会返回退出代码 6,它一定来自 Mono,但我在任何地方都找不到它的记录。
我可以从 PHP 调用任何其他内容,因此安全模式或任何类似的限制不会阻止我从 PHP 执行外部程序。
谢谢你的任何想法...
it's a bit complicated. :-) I have a website written in PHP that needs to call an external program written in .NET, running under Mono. It calls the program with:
/path/mono /path/executable arguments...
as per usual (I also tried to put this into a bash script and call the script itself from PHP).
As far as I can tell, everything is set up as required. Mono itself running all right, executable (or script) with executable rights, owners are all right. The correct setup can also be ascertained from the fact that if I issue the command line above (or call the script mentioned) from a command line on the server (Debian Lenny), everything works perfectly, my executable is executed without error.
But, if PHP calls the same (using exec(), system() or any other variant), I immediately get an exit code of 6 from Mono and my executable is not run at all (in order to test it, I use a "Hello World" executable that does nothing but emits a single output line and returns 0). Compiled without any additional dependency, just a real "Hello Word". It's absolutely sure that this program doesn't return the exit code 6, it must come from Mono but I couldn't find it documented anywhere.
I can call anything else from PHP, so it's not safe mode or any similar restriction that would keep me from executing external programs from PHP.
Thanks for any idea...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试从命令行执行 mono,但用户运行网络服务器(www-data 或 apache)。
ej。
我使用 exec 时遇到的常见问题是不同的环境变量(看看 apache 使用的是 bash 或 sh)、apache 用户/组的权限等。
Try to execute mono from the command line but with the user running the webserver (www-data or apache).
ej.
The common problems that I have using exec is a different environment variables (look if is bash or sh what apache is using), permissions to the user/group of apache, etc.