How to make asynchronous HTTP requests in PHP

后端 未结 18 2363
梦如初夏
梦如初夏 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 02:53

    class async_file_get_contents extends Thread{
        public $ret;
        public $url;
        public $finished;
            public function __construct($url) {
            $this->finished=false;
            $this->url=$url;
        }
            public function run() {
            $this->ret=file_get_contents($this->url);
            $this->finished=true;
        }
    }
    $afgc=new async_file_get_contents("http://example.org/file.ext");
    

提交回复
热议问题