cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

curl_multi_init() ??

From: Ben Periton <ben.p_at_xtechmedia.co.uk>
Date: Sat, 23 Oct 2004 11:39:22 +0100

Hi,

 

Im trying to get PHP5 and curl to check multiple TCP ports at once using
curl_multi_init()

This works fine, but im stuck on how to return the status of each individual
request?

 

When I run my code it prints out that all the ports are down, when I know
that they are up.

 

Does anyone have any examples of this, or where I can find some docs on it.

 

Regards

Ben Periton

 

My code is as follows:

 

$connections = array();

for ($i=0; $i<sizeof($allHosts); $i++) {

            $details = array($allHosts[$i]->get_host(),
$allHosts[$i]->get_port(), $allHosts[$i]->get_frequency(),
$allHosts[$i]->get_status(), $allHosts[$i]->get_lastchecked());

            $connections[] = $details;

}

 

$fetch = curl_multi_init();

 

foreach ($connections as $i => $portdetail) {

       $conn[$i]=curl_init($portdetail[0]);

       curl_setopt($conn[$i],CURLOPT_PORT,$portdetail[1]);

       curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);

       curl_setopt($conn[$i],CURLOPT_VERBOSE,1);

       curl_multi_add_handle ($fetch,$conn[$i]);

}

 

do { $n=curl_multi_exec($fetch,$active); } while ($active);

 

foreach ($connections as $i => $portdetail) {

            $result = curl_multi_info_read($conn[$i]);

            

            if ($result) {

                        print 'UP '.$result.'<br>';

            } else {

                        print 'DOWN '.$result.'<br>';

            }

            

            curl_close($conn[$i]);

}
Received on 2004-10-23