Answer the question
In order to leave comments, you need to log in
How to properly run shell_exec in yii2?
Good day to all. There is a project - a bot for Instagram, which authorizes itself, likes, unsubscribes, etc. The database contains several thousand accounts from Instagram. The project has a controller on yii2 called BotController, there are several functions there. For example, there is a login function, it looks into the database if there is an active task, if there is, it logs in under the user who created this task. Further, according to the logic, the like, fall, unfollow function should start (that is, this user should like, subscribe to someone and unsubscribe).
I want to run all this through shell_exec to parallelize. How to do it? Help, I'm new to shell_exec
Answer the question
In order to leave comments, you need to log in
Yes, there seems to be nothing special about launching via shell_exec. The documentation page is full of examples php.net/manual/en/function.shell-exec.php .
I think in your case queues would be more suitable. It may be a little early for you, but still look towards Gearman or ZeroMQ.
The fact is that launching via shell_exec will most likely be synchronous, i.e. your BotController will wait until the process generated by it ends and you will not get any speed gain. Although there are examples here of how you can run asynchronously stackoverflow.com/questions/222414/asynchronous-sh... you will have to figure out how to transfer the result of the task back to the main thread.
i did that
private static function runConsole($command, &$status)
{
$cmd = $command . ' 2>&1';
$handler = popen($cmd, 'r');
$output = '';
while (!feof($handler)) {
$output .= fgets($handler);
}
$output = trim($output);
$status = pclose($handler);
return $output;
}
var_dump(Helper::runConsole('ls'));
There is a library: https://github.com/vova07/yii2-console-runner-extension
Cross-platform.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question