search

Home  >  Q&A  >  body text

php - SESSION cannot be used when the queue is executed asynchronously, so can I still use the queue when logging in?

SESSION cannot be used when the queue is executed asynchronously, so can I still use the queue when logging in? If so, how can I deal with the corresponding relationship between cookies and sessions?

怪我咯怪我咯2807 days ago398

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-16 13:07:36

    Can I still use the queue when recording?

    Login is usually a synchronous process. Using a queue is not impossible, but it will increase complexity.

    The synchronous login process is to read the database, determine the correct account and password, and set up the session, which can be completed in one HTTP request.

    Changing to asynchronous, I can only think of the following method:

    1. Client generates random token

    2. The client sends the token, account number, and password to the server

    3. The server records this token in redis and has not logged in successfully

    4. The server puts the token, account, and password into the queue for processing

    5. Queue processing, if the account is correct, the token in redis is marked as successful, otherwise it is marked as failure

    6. During the process of server and queue processing, the client keeps using another interface to poll to see if the token login is successful. If successful, all subsequent requests will bring the token, otherwise the client login fails.

    So the synchronous login process should be completed as soon as possible, and some operations required after login (sending email notifications, etc.) should be queued instead of the entire login process.

    reply
    0
  • Cancelreply