Simple way to execute external program in Slimframework

By default, PHP has more options to execute the external programs or commands via command line like exec() , shell_exec () and etc… But while using this core function for external command then it hard to handle the exception which means some time we are could not able to figure out exact exception. For this , we go to use top of the symfony component which is symfony process.

Why should i use symfony process?

  • Easy to handle the Exception
  • It suitable for long running process

Ok. When comes to the implementation , I have used light weight Slimframework and Symfony Process component

Create composer.json at your project root folder. Here is my example project structure

Add the following code to that composer.json file

Then make install composer by using following command.

Then create index.php to start the application

In index.php, initiate the slim application

Then index.php, Use the symfony process component like this

That’s it. More info about Symfony Process

Thank you. Don’t forgot to share and subscribe for my latest updates.


  • Cristi Nebunu

    Hey there, I have a problem, if you still monitor this post. If I install Symfony Process, I get a middleware not found error in Slim 2. Any Idea why ?