2016-08-31 05:20



I am newbie in Laravel and building a small project for practice.

There is one registration form and up to 100 registration done a day approx.

It return me status->pending of user.

Now my question come here that, php execution time for connection with remote Api is 30 second as per my knowledge.

Then, how can I handle the cron job in such a condition where I need to call remote api for receiving the data for every user status if it becomes "accepted" or "rejected" or still in "pending"

I am struggling with this condition and my database structure like

userId - status - created_at - updated_at

I need to call it after 20 hours if possible for all user or every 4 hours if we cannot call them at once.

What will be the best practise to do it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongtui8593 dongtui8593 5年前

    For long-running tasks, two options come to my mind:

    Task Queues

    Use an asynchronous task queue. They are designed for long-running tasks. Schedule one job for each newly registered user. Be sure to set the timeout longer than your estimated 30s. Pass the user instance to the constructor of the job and store it to an instance variable. From within the handler, just update the record directly.


    Implement a callback via http. This requires control over the remote api. When calling the remote api, you would submit a callback url, such as https://local-app.domain/callbacks/finished-check-user/223 where 223 is the id of the user. The remote api would send a http request to the given url after it's finished processing. In your local app, have a controller handle the request, fetch the user by its id and update it with the data received from the remote api in the request body. Don't forget to make sure the request is authentic.

    Does this help?

    点赞 评论 复制链接分享