search

Home  >  Q&A  >  body text

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?

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?
阿神阿神2827 days ago449

reply all(8)I'll reply

  • ringa_lee

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

    reply
    0
  • 黄舟

    黄舟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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:12:48

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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-16 13:12:48

    If the timeliness is not strong. Recommended to cache

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:12:48

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

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:12:48

    Doesn’t PHP even have asynchronous callbacks? Hey

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-16 13:12:48

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:12:48

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

    reply
    0
  • Cancelreply