How to make asynchronous HTTP requests in PHP

后端 未结 18 2037
梦如初夏
梦如初夏 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 03:06

    /**
     * Asynchronously execute/include a PHP file. Does not record the output of the file anywhere. 
     *
     * @param string $filename              file to execute, relative to calling script
     * @param string $options               (optional) arguments to pass to file via the command line
     */ 
    function asyncInclude($filename, $options = '') {
        exec("/path/to/php -f {$filename} {$options} >> /dev/null &");
    }
    

提交回复
热议问题