Page 1 of 1

PHP forking

Posted: Mon Oct 04, 2010 6:43 pm
by kumarrana
I read some article about forking and optimizing the performance. I am writing a program that query the satellite modem's status. It became painful once I realize that there is quarter second delay to reach the host and return the value. On top, I have 255 loops to go through, means big latency. On my old box, it takes more than 10 minutes to finish one iterations. Can somebody help me to adapt either forking to optimize the loop or direct me to other paths. Here is my sample code.

Code: Select all

$EventDescriptionOID = ".1.3.6.1.4.1.XXXX.34.1.3.3.1.1.4."
$IP = "192.XXX.XXX.XXX";
for ($i = 1; $i <= 255; $i++)
{
$Get625EventDescription = shell_exec("/usr/bin/snmpget -c public -v 2c $IP $EventDescriptionOIDArr | awk '{print $4 $5 $6 $7 $8}'");  
echo "Index is: $EventDescriptionOIDArr" . " Query is: $Get625EventDescription <br>" ;
}

Re: PHP forking

Posted: Mon Oct 04, 2010 9:29 pm
by requinix
How much do you know about multithreading and forking? Do you have a strategy in mind for how to use it?

Re: PHP forking

Posted: Mon Oct 04, 2010 9:39 pm
by John Cartwright
2nd post in a row where I would recommend another language suited for multithreading, i.e., c#.

By forking you are creating an additional process or each fork, which is not good when you want to fork 250 odd processes.

Re: PHP forking

Posted: Mon Oct 04, 2010 11:02 pm
by s.dot

Re: PHP forking

Posted: Tue Oct 05, 2010 1:48 am
by kumarrana
I know very little about multi-threading and forking actually. I have been programming on PHP for over 5 years, but it was on and off. I am back after nearly 2 years. I do have strategy to use. I will go through the link that s.dot posted. I like John's advice but it is already too late to adapt new language. Ideal help from you guys would be a simple example that is similar to the code I posted.

Re: PHP forking

Posted: Tue Oct 05, 2010 5:56 pm
by Weirdan
What is actually different for every iteration (it's not clear from the code you posted)? If it's OID that changes, than you may issue a single request with multiple oids specified and suffer the roundtrip only once.

Re: PHP forking

Posted: Tue Oct 05, 2010 11:32 pm
by kumarrana
The last digit of OID will go from 1 to 255. So there will be 255 unique OIDs incrementing last digit from 1. Sorry about the confusion, I copied from working program just to show how I am doing, and asking for better solution.

Re: PHP forking

Posted: Wed Oct 06, 2010 3:54 am
by Weirdan
kumarrana wrote:The last digit of OID will go from 1 to 255. So there will be 255 unique OIDs incrementing last digit from 1. Sorry about the confusion, I copied from working program just to show how I am doing, and asking for better solution.
So you could do something like this:

Code: Select all

$EventDescriptionOID = ".1.3.6.1.4.1.XXXX.34.1.3.3.1.1.4."
$IP = "192.XXX.XXX.XXX";
$oids = array();
for ($i = 1; $i <= 255; $i++)
{
   $oids[] = $EventDescriptionOID . $i;
}

var_dump(shell_exec("/usr/bin/snmpget -c public -v 2c " . escapeshellarg($IP) . " " . join(' ', array_map('escapeshellarg', $oids)) . "| awk '{print $4 $5 $6 $7 $8}'"));  

Re: PHP forking

Posted: Thu Oct 07, 2010 7:38 pm
by kumarrana
Thanks Weirdan, I will implement your code and tell you how it go through.