PHP - How to directly execute the next line of code when accessing an API that takes a long time to execute, regardless of its execution time and return value?
阿神
阿神 2017-05-16 13:10:48
0
8
444

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?
阿神
阿神

闭关修行中......

reply all(8)
左手右手慢动作

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/...

黄舟

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

伊谢尔伦

Young man, I will teach you two words of mantra: Team! List!

phpcn_u1582

If the timeliness is not strong. Recommended to cache

曾经蜡笔没有小新

fastcgi_finish_request() can satisfy you, only supported by php-fpm. . Or create a queue service

为情所困

Doesn’t PHP even have asynchronous callbacks? Hey

世界只因有你

Swoole process management is different for PHP. See swoole process management

巴扎黑

Isn’t this asynchronous transmission technology? It’s also possible without using sockets

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template