How to make asynchronous HTTP requests in PHP

后端 未结 18 2278
梦如初夏
梦如初夏 2020-11-22 02:13

Is there a way in PHP to make asynchronous HTTP calls? I don\'t care about the response, I just want to do something like file_get_contents(), but not wait for

18条回答
  •  遇见更好的自我
    2020-11-22 03:08

    You can use non-blocking sockets and one of pecl extensions for PHP:

    • http://php.net/event
    • http://php.net/libevent
    • http://php.net/ev
    • https://github.com/m4rw3r/php-libev

    You can use library which gives you an abstraction layer between your code and a pecl extension: https://github.com/reactphp/event-loop

    You can also use async http-client, based on the previous library: https://github.com/reactphp/http-client

    See others libraries of ReactPHP: http://reactphp.org

    Be careful with an asynchronous model. I recommend to see this video on youtube: http://www.youtube.com/watch?v=MWNcItWuKpI

提交回复
热议问题