Asynchronous Function Call in PHP

前端 未结 7 1522
逝去的感伤
逝去的感伤 2020-11-30 20:54

I am working on an a PHP web application and i need to perform some network operations in the request like fetching someone from remote server based on user\'s request.

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 21:43

    Nowadays, it's better to use queues than threads (for those who don't use Laravel there are tons of other implementations out there like this).

    The basic idea is, your original PHP script puts tasks or jobs into a queue. Then you have queue job workers running elsewhere, taking jobs out of the queue and starts processing them independently of the original PHP.

    The advantages are:

    1. Scalability - you can just add worker nodes to keep up with demand. In this way, tasks are run in parallel.
    2. Reliability - modern queue managers such as RabbitMQ, ZeroMQ, Redis, etc, are made to be extremely reliable.

提交回复
热议问题