Php itself is not asynchronous, but we often need to handle some time-consuming operations, such as pushing a public number to all users. I have tried many methods and have not done this. Each piece pushes a network request. The curl seems to be at least one second at a time, and the number of requests is too many. Fscokopenpostjson data is not... php itself is not asynchronous, but we often need to handle some time-consuming operations, such as pushing a public number to all users. I have tried many methods and have not done this. Each piece pushes a network request. The curl seems to be at least one second at a time, and the number of requests is too many. Fscokopen post json data has not been solved, and post data empty has always appeared. Please give some solutions to each of your experts!
Reply content:
Php itself is not asynchronous, but we often need to handle some time-consuming operations, such as pushing a public number to all users. I have tried many methods and have not done this. Each piece pushes a network request. The curl seems to be at least one second at a time, and the number of requests is too many. Fscokopen post json data has not been solved, and post data empty has always appeared. Please give some solutions to each of your experts!
Time-consuming operations do not need to be placed on the web. You can use php to write scripts to put time-consuming operations in the web, and then execute the script on the web and ignore the output to achieve the asynchronous effect. This is my method, if you see a better answer, remember @ I'll take a look at Hahaha. The following is the sample code:
Pclose (popen ('/usr/local/php5/bin/php tmp. php &', 'R'); // continue your code
You can use gearman for php
Or swoole.
Message Queue is available.
Message Queue processing time-consuming task, gearman php-resque
Or fastcgiFinishRequest
You can use the redis queue to implement the progressive push function. The implementation principle is relatively simple, and redis is fast to execute.
Store time-consuming tasks in the database, and then write a php cli process to process the tasks in the database cyclically.
These time-consuming tasks should not be executed on the Web (MOD_PHP, PHP-FPM) to avoid affecting Web Services.
Php + rabbitmq, "pushed to all users by the public" as a separate module, each time a message needs to be sent, it can be placed in the message queue, and all subsequent messages will be handed over to rabbitmq for processing.
Same as above, php + rabbitmq, "public number push to all users" as a separate module, each time a message needs to be sent, it can be placed in the message queue, and all subsequent messages are handed over to rabbitmq for processing.