Re: Executing functions or scripts in parallel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sure, sorry about that. I have a function that tells me if the host is DOWN
or UP. I want to run this function in parallel for each host I monitor. The
function is the following:

function servstatus($remote_ip, $remote_ip_port, $remote_ip_proto) {

if ($remote_ip_proto == "tcp") {
       $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

       // Turning Off Warning Messages
       $i_error_old=error_reporting();
       error_reporting($i_error_old & ~ (E_WARNING));

       if ($connect = socket_connect($socket, "$remote_ip", "" .
$remote_ip_port . "")) {
               return true;
               socket_set_block($socket);
               socket_close($socket);
               unset($connect);
       } else {
               return false;
               socket_set_nonblock($socket);
               socket_close($socket);
               unset($connect);}

} else {

       // Turning off Warning Messages
       $i_error_old=error_reporting();
       error_reporting($i_error_old & ~ (E_WARNING));

       $socket = fsockopen("udp://$remote_ip", "$remote_ip_port", &$errno,
&$errstr, 2);
       $timeout = 1;

       if (!$socket) {
               return true;
       }

       socket_set_timeout ($socket, $timeout);
       $write = fwrite($socket,"\x00");
       if (!$write) {
               return true;
       }

       $startTime = time();
       $header = fread($socket, 1);
       $endTime = time();
       $timeDiff = $endTime - $startTime;

       if ($timeDiff >= $timeout) {
               fclose($socket);
               return true;
       } else {
               fclose($socket);
               return false;
       }
       }
}


Thanks in advance

Felipe Martins

On 5/30/06, Dave Goodchild <buddhamagnet@xxxxxxxxx> wrote:



On 30/05/06, Phil Martin <darkinner.lists@xxxxxxxxx> wrote:
>
> Hi everyone,
>
>       I've made a very basic and small function to suit my needs in
> monitoring some hosts services. I've noticed that the script is a little
> bit
> slow because of the number of hosts and services to monitor. Is there a
> way
> to execute my function servstatus();  in parallel with every hosts to
> increase the speed ?
>       Thanks in advance.
>
> []'s
> Felipe Martins
>
>
Can you show us the function?

--
http://www.web-buddha.co.uk

dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml, css)

look out for project karma, our new venture, coming soon!


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux