As in the title:
In fact, I probably want to trigger a program through the API when opening a page, but this program executes relatively slowly. I don’t want to worry about its execution and return in the page. After triggering the request, I can directly Continue to execute the following code. Please tell me how to use PHP code to implement this situation?
ringa_lee2017-05-16 13:12:48
The method mentioned by
@dawnblog is indeed possible, but the subject's requirement only requires a simple trigger with fsockopen
, and there is no need to process callback data.
Reference: http://www.laruence.com/2008/...
黄舟2017-05-16 13:12:48
Let me tell you this, if you want to start the program asynchronously, it is not impossible, you can use socket
Specific implementation steps
1. Send instructions to the socket server
2. Socket receives instructions and sends them asynchronously through long links Send the command to another task processing server
3. The socket directly tells the web server to receive the command and execute it, but the task is executed through the task processing server. ---- This step is equivalent to asynchronous ajax execution
4. The task processing server is completed After that, send the completion command to the socket server.
5. The socket server completes the specified task completion logic.
You can refine it in step 5. Of course, this is how I handle asynchronousness. If there are other better ones Please point out any deficiencies in the method.
Please check workman for the specific implementation of the above code
曾经蜡笔没有小新2017-05-16 13:12:48
fastcgi_finish_request() can satisfy you, only supported by php-fpm. . Or create a queue service
世界只因有你2017-05-16 13:12:48
Swoole process management is different for PHP. See swoole process management
巴扎黑2017-05-16 13:12:48
Isn’t this asynchronous transmission technology? It’s also possible without using sockets