Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call shell commands from Laravel controller?

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.

like image 464
zafus_coder Avatar asked Oct 23 '14 11:10

zafus_coder


2 Answers

You can use the Process component provided by Symfony: http://symfony.com/doc/current/components/process.html

The component is used by Laravel itself, so your don't need to install it via composer separately. Just add use Symfony\Component\Process\Process; to your file.

If you use it(instead of php's exec() function), you'll be able to unit test the code that calls shell commands.

like image 135
Emil M Avatar answered Oct 10 '22 23:10

Emil M


It all depends on what operating system you are using. php already has a few functions to execute shell commands.

Laravel has a build in task runner for ssh commands.

like image 27
Jerodev Avatar answered Oct 11 '22 00:10

Jerodev