1

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:

slince
  • 21
  • 2

1 Answers1

0

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

fgamess
  • 1,276
  • 2
  • 13
  • 25
  • Hi, thanks! you may not understand my problem; the hot patch is for my customers, they use my project; I hope they can complete the patch update with a few clicks on the browser; like a button "Click to Update" – slince Jul 10 '18 at 05:53
  • 1
    Hi, You want to fix a bug found in the code right? So you deploy the new version of the code to your production environment? If you want, you can create an action controller so when the user clicks on "Click to Update" you execute the CLI code inside the controller, then it clears the cache that's all. – fgamess Jul 10 '18 at 05:56