Thomas Crawford
Thomas Crawford

Reputation: 896

Run Console Command in PHP script Symfony 2

i have this console command :

php app/console jms-job-queue:run

I want to run this command when i click a button on my website. So i don't niet a command prompt to do this.

Is this possible in symfony 2 ?

Upvotes: 1

Views: 1469

Answers (4)

mangelsnc
mangelsnc

Reputation: 148

You can define the command as a service like this and use it in your controller.

Upvotes: 0

Cristian Bujoreanu
Cristian Bujoreanu

Reputation: 1167

A good idea would be to created a helper class to do this for you, because the commands will look different foreach dev and prod environment. You can add also methods to check if there are any processes running, or to kill one.

Not sure, but I guess you need full path to your command:

[%kernel.root_dir%] / console jms-job-queue:run

Upvotes: 2

Jason Roman
Jason Roman

Reputation: 8276

Your could try creating a service that defines the behavior you want, then have both your console command and your controller action call that service. This promotes code reuse and allows you to call that function anywhere you want.

You can also look at this question that had been answered before: How can I run symfony 2 run command from controller

Upvotes: 1

asyndrige
asyndrige

Reputation: 592

Maybe it will be enough to use plain php exec function.

Upvotes: 0

Related Questions