"how do i make an asynchronous get request in php?" Code Answer


file_get_contents will do what you want

$output = file_get_contents('http://www.example.com/');
echo $output;

Edit: One way to fire off a GET request and return immediately.

Quoted from http://petewarden.typepad.com/searchbrowser/2008/06/how-to-post-an.html

function curl_post_async($url, $params)
    foreach ($params as $key => &$val) {
      if (is_array($val)) $val = implode(',', $val);
        $post_params[] = $key.'='.urlencode($val);
    $post_string = implode('&', $post_params);


    $fp = fsockopen($parts['host'],
        $errno, $errstr, 30);

    $out = "POST ".$parts['path']." HTTP/1.1rn";
    $out.= "Host: ".$parts['host']."rn";
    $out.= "Content-Type: application/x-www-form-urlencodedrn";
    $out.= "Content-Length: ".strlen($post_string)."rn";
    $out.= "Connection: Closernrn";
    if (isset($post_string)) $out.= $post_string;

    fwrite($fp, $out);

What this does is open a socket, fire off a get request, and immediately close the socket and return.

By stormi-7124c6085adc on August 8 2022

Answers related to “how do i make an asynchronous get request in php?”

Only authorized users can answer the search term. Please sign in first, or register a free account.