samedi 1 juin 2019

Listen to incoming request for specific time inside laravel controller

I'm working on a game.

This is the scenario:

  1. First player request a challenge
  2. system will wait 5 seconds for another request
  3. IF another request does not come, system start a challenge with a bot

All three steps have to run in backend and As much as I know, there's some functions like sleep or usleep in php that will wait some specific seconds and then continue the code.

In my case I do not want my controller to sleep.

Note:

As you may know, I'm using laravel.

Does any one experience about this case?

public function start()
{
    $game = new \App\Models\Game();
    $lastGame = $game->orderBy('id', 'desc')->first();

    if( $lastGame->user_one != false && $lastGame->user_two == null )
    {
        return 'can join';
    }
    else if( $lastGame->user_one != null && $lastGame->user_two != null )
    {
        return 'newGameShould Create...';
    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire