I'm working on a project using PHP and Yii2 framework. It has a task that requires making many requests to get data through API and it takes like one minute to finish. To avoid keeping the user waiting, I tried to use exec() function and redirect the output to other file. To make better UX
I tried this code in separated PHP files (outside Yii) and it work perfectly.
exec("php process.php > output.php 2>&1 & echo $!", $output);
once I tried to execute it in Yii using the following, it doesn't work.
public function actionIndex() {
$url = Url::to(['user/dofile'], TRUE);
exec("php $url > testoutput.php 2>&1 & echo $!", $output);
return $this->render('index');
}
The error appears
Could not open input file: http://localhost/weez/frontend/web/index.php?r=user%2Fdofile
Is there a way to make it work in Yii actions?
Is there alternative ways to accomplish that
Thank you
You can't execute like php $url and expect php to parse it. try curl -O $url.
But a better option to supplement the original issue ("avoid keeping the user waiting"), try implement "queuing".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With