sirexzib
2 years ago

Laravel Artisan Commands from route times out

Posted 2 years ago by sirexzib

I've been trying to solve an issue forever, I have a command I need to run but when I execute it from a GET request it times out after like 60 seconds.

So someone told me to make a CLI command or Artisan command and do it that way, and so I did but it did the exact same thing, after 60-75 seconds the page returns 502 bad gateway and the issue remains.

How do I make it so when you go the URL, it submits it to start running and it runs on the server rather than the get request? Cause when I go to the URL for the command, it loads and loads and at the same time the command runs but when the connection closes the command closes aswell.

This is my code:

== Command ==

public function handle()
{
  $users = User::all();

     foreach($users as $user){
         $invested = 0;
         $networth = 0;




         $stats = Stat::where('userid', $user->id)->first();
         $bittrex_trades = 0;
         $polo_trades = 0;

         if($bittrex_trades == 0 && $polo_trades == 0)
         {
           if($stats){
                $stats->legit = $user->getMoney();
                $stats->save();


           } else {
               $stats = new Stat;
               $stats->legit = $user->getMoney();
               $stats->userid = $user->id;
               $stats->currency = $user->currency;
               $stats->save();
           }
       }
     }
}

== Route ==

Route::get('/test1231', function () { $exitCode = Artisan::call('update:profit', ['--queue' => 'default']); });

Please sign in or create an account to participate in this conversation.