When I try to run that phing command: bin/phing clear_cache_action from a console, everything works. Unfortunately, when I try to run the same command from the controller in the Symfony project I get an error.
That my code:
public function clearAction()
{
$process = new Process('bin/phing clear_cache_action');
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
}
Symfony returns me that error:
The command "bin/phing clear_cache_action" failed.
Exit Code: 127(Command not found)
Working directory: /var/www/caolin/web
Output:
================
Error Output:
================
sh: 1: bin/phing: not found
Linux commands e.g. 'ls' works properly. How can I run phing command from code?
I guess you are trying to execute
phingfrom aController. ThusWorking directory: /var/www/caolin/webinstead of/var/www/caolincauses resolvingbin/phingto/var/www/caolin/web/bin/phingwhich does not exist. You should set your current working directory to%kernel.project_dir%:However, I would not recommend starting a process from a Controller unless you are really sure what you are doing.