Re: Executing functions or scripts in parallel
| From: | Phil Martin | Date: | Tue, 30 May 2006 15:43:06 +0000 |
| Subject: | Re: Executing functions or scripts in parallel | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237090@lists.php.net to get a copy of this message | ||
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@gmail.com> wrote:
On 30/05/06, Phil Martin <darkinner.lists@gmail.com> wrote: Hi everyone,I've made a very basic and small function to suit my needs inmonitoring 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!