T
T
Talgat Baltasov2015-06-29 13:24:56
Yii
Talgat Baltasov, 2015-06-29 13:24:56

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

3 answer(s)
M
matperez, 2015-06-29
@matperez

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.

M
Mirocow, 2016-05-08
@mirocow

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'));

M
Micro Null, 2018-04-24
@micronull

There is a library: https://github.com/vova07/yii2-console-runner-extension
Cross-platform.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question