php 从 Laravel 控制器调用 shell 命令?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26527091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call shell commands from laravel controller?
提问by zafus_coder
Is it possible to call Shell commands (e.g for converting images ) from laravel controller? If yes then how. I have searched on internet. Nothing seems relevant. Please Guide.
是否可以从 Laravel 控制器调用 Shell 命令(例如用于转换图像)?如果是,那么如何。我在互联网上搜索过。似乎没有什么相关的。请指导。
Thanks
谢谢
回答by Emil M
You can use the Process component provided by Symfony: http://symfony.com/doc/current/components/process.html
您可以使用 Symfony 提供的 Process 组件:http: //symfony.com/doc/current/components/process.html
The component is used by Laravel itself, so it can be loaded directly.
该组件是 Laravel 自己使用的,所以可以直接加载。
If you use it(instead of php's exec()
function), you'll be able to unit test the code that calls shell commands.
如果您使用它(而不是 php 的exec()
函数),您将能够对调用 shell 命令的代码进行单元测试。
回答by Jerodev
It all depends on what operating system you are using. php already has a few functionsto execute shell commands.
这完全取决于您使用的操作系统。php 已经有一些函数来执行 shell 命令。
Laravel has a build in task runner for sshcommands.