too long

I am quite new to working with PHP and for a current project I am running an external API that returns ping results from various servers. I then use this information to display 'live' events on a webpage.

Running a request for all servers at once will take minutes to return results, so I want to break up each server as a separate request. However, creating a foreach loop and looping through a single request for each server is still not returning me the results until the loop has finished.

I'm now thinking my best option will be to set up some kind of asynchronous processing (multi thread) a function to send out each request on it's own separate thread.

Is this easily possible with PHP? I simply need to send off an AJAX call, get the results and publish to a database. However, I do need to run this continuously over and over.

Note: I am using PHP version 5.5.12 and did try briefly to venture down the path of pthreads but it seemed to break my MSSQL thread safe drivers and temporarily kill my web application. I'm guessing it may not be a fairly straight forward process.

Thanks to the suggestion from $Dagon, I decided to venture down the path of curl_multi. Utilising an example found on the php.net website, I added the following function:

function multiCurl( $res, $options="" ) {

    if( count( $res ) <= 0 ) return False;

    $handles = array();

    if( !$options ) // add default options

        $options = array(
            CURLOPT_HEADER          => 0,
            CURLOPT_RETURNTRANSFER  => 1
        );


    // add curl options to each handle
    foreach( $res as $k => $row ) {

        $ch{$k} = curl_init();
        $options[CURLOPT_URL] = $row['url'];
        $opt = curl_setopt_array( $ch{$k}, $options );
        //var_dump( $opt );
        $handles[$k] = $ch{$k};

    }

    $mh = curl_multi_init();

    // add handles
    foreach( $handles as $k => $handle ) {

        $err = curl_multi_add_handle( $mh, $handle );

    }

    $running_handles = null;


    do {

        curl_multi_exec( $mh, $running_handles );
        curl_multi_select( $mh );

    } while( $running_handles > 0 );


    foreach( $res as $k=>$row ) {

        $res[$k]['error'] = curl_error( $handles[$k] );

        if( !empty( $res[$k]['error'] ) ) {

            $res[$k]['data']  = '';

        } else {

            $res[$k]['data']  = curl_multi_getcontent( $handles[$k] );  // get results

        }

        // close current handler
        curl_multi_remove_handle( $mh, $handles[$k] );

    }

    curl_multi_close( $mh );

    return $res; // return response

}

Even though results are still presented after all url's have been executed, feeding in my array of 60+ server addresses, returned me a response time of around 10 or so seconds, compared to around a minute (for a single ping each server).

Exactly what I needed.