0

I am using two frameworks i.e. Laravel and Symfony for two applications which are interlinked with each other. Both are having bash script.

Now, I want to write 'php artisan down' command in Symfony's bash script so that if I merge code to Symfony then both the applications gets down.

How can I write Laravel artisan command in Symfony framework?

2 Answers 2

1

It should work like any other command:

#!/bin/bash
php /full/project/path/artisan down

Just write the full path.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, also I want to write Symfony 'sudo supervisorctl stop all' in laravel bash script. How to do that
Just add the command to the script below the artisan, but you can't sudo inside of a bash script, the whole bash script must be run as superuser.
1

You can do this in your Symfony project using Symfony Console:

//in your symfony project
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;


public function processCmd() {
    $process = new Process('php /absolute/path/to/project/artisan down');
    $process->run();
    if (!$process->isSuccessful()) {
        throw new ProcessFailedException($process);
    }
    echo $process->getOutput();
}

Update:

Laravel also uses the same symfony's Console component! So if you want to run something in Laravel, you can use the same code above.

Example:

    //in your laravel project 
    use Symfony\Component\Process\Process;
    use Symfony\Component\Process\Exception\ProcessFailedException;
    
    
    public function processCmd() {
        $process = new Process('supervisorctl stop all');
        $process->run();
        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process);
        }
        echo $process->getOutput();
    }

P.S:

You can pass an array if you want to run multiple commands:

 $process = new Process(array('ls', '-lsa'));

1 Comment

I want all these in bash script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.