How to make asynchronous HTTP requests in PHP

后端 未结 18 2368
梦如初夏
梦如初夏 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:06

    Here is a working example, just run it and open storage.txt afterwards, to check the magical result

     4) exit;
        if($i == 1) file_put_contents('storage.txt', '');
    
        file_put_contents('storage.txt', file_get_contents('storage.txt') . time() . "\n");
    
        sleep(5);
        curlGet($_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?i=' . ($i + 1));
        curlGet($_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?i=' . ($i + 1));
    

提交回复
热议问题