How can I apply the hot patch to fix bugs in the symfony project?

326 Views Asked by At

I have an application using symfony3 and some customers use it. I plan to fix the bug by downloading the patch code online.

But you know that when the patch code overwrites the project code, you must execute the following command to make the patch code take effect.

php php bin/console cache:clear --env=prod chmod -R 777 var/tmp

Unfortunately, this command can only be executed in cli mode;

How can I implement this function?

Finally, please forgive me for my bad English. :simle:

1

There are 1 best solutions below

2
fgamess On

You can use Symfony Process Component to achieve this:

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

$process = new Process('php bin/console cache:clear --env=prod && chmod -R 777 var/tmp');
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}

echo $process->getOutput();

You have multiple solutions in fact:

  • Implement this code in a controller only accessible by you.
  • If you use a deployer like capistrano, ansible or any other technology, just add the cli command you want to execute and trigger execution after deploying the patch.

you can also create a Symfony Command to wrap you cli commands