Reputation: 605
My basic objective is to acheive asynchornous triggers in PHP using Yii2 Web Application
I need to run the php batch jobs but i dont want to wait in the browser / cron for doing the job. For running the job i need to use different file of my application like
http://myapp/foojob.php
The foojob.php should be asynchronously call many php instances[Each instance carries one job] based on the availble jobs in hand. The time limit of the call (foojob.php) is less than 60sec.i need to trigger new php instances before it exceeds timeout value.
The application is self-hosted product . it would get work on Various hosting services . Shared Hosting won't allow / Provide any external extensions for their customer .
Upvotes: 6
Views: 1104
Reputation: 605
I have wrote one php library for non blocking background jobs. This Library would helps to achieve the objective i posted
Composer Library https://packagist.org/packages/devbabuind/non-blocking-php
Upvotes: 0
Reputation: 1960
You could take an approach where you send the correct headers to have the browser close the connection and then run the process synchronously and it would appear to be async to the end user.
Here is something I wrote a long time ago that you can see as an example. http://www.phpclasses.org/package/8388-PHP-Defer-execution-of-actions-until-the-script-ends.html
I assume there is some place in yii that you could hook into after the content is sent where you could do a similar thing.
Short version of it header("Content-Length: ".$length); header("Connection: Close");
ob_flush(); // headers
echo $html;
flush();
doWork();
Upvotes: 1