I need to run some business logic in the background when the request is received.
Could anyone please share what will be the proper way to implement this?
I need to run this in shared hosting
public function runSync()
{
// `Variables` Db table to store current value is sync is running or not
$res = Variables::where('key', 'sync')->first();
if($res!= null && $res->value=="true" )
{
return response('Sync already running');
}
if( $res == null)
{
$syncvar = new Variables;
$syncvar->value="true";
$syncvar->key="sync";
$syncvar->save();
}
//*** process my data here
//** don't wait for this block
// return response to user
return response('Sync has started..');
}