I've been working with PHP (I'm very new to this) and I have this scenario:
I have a list with 3 (or more) IP addresses + ports that comes from a file, so each line of my file has:
192.168.3.41:8013
192.168.3.41:8023
192.168.3.41:8033
So in my array, these are elements array[0], array[1], array[2]
. The purpose of the application is simple, ping the IP:PORT and know if it is responding and how many ping errors it has. But that is not all, I have to count the time it takes to do the process for 3 minutes and 1 minute. So, I've been asked to work with MemCache to do the following:
For each IP:PORT, I need to save in MemCache how many errors does I have in 3 minutes as well as the number of errors I have in 1 minute, so something like that:
For number of errors in 3 minutes
Map<Key, Value> = Map<IP:PORT, NumberOfErrors3Mins>
For number of errors in 1 minute
Map<Key, Value> = Map<IP:PORT, NumberOfErrors1Min>
So, a data sample could be like this:
For 3 minutes:
<192.168.3.41:8013, 5>
<192.168.3.41:8023, 2>
<192.168.3.41:8023, 0>
For 1 Minute:
<192.168.3.41:8013, 3>
<192.168.3.41:8023, 1>
<192.168.3.41:8023, 1>
So, I have two maps and 3 entries for each map. I'm pretty new to PHP and MemCache is kind of difficult to me, the logic I stablished is the following:
$array = array('192.168.3.41:8013','192.168.3.41:8023','192.168.3.41:8033');
for ($i = 0; $i < count($array); ++$i){
$currentProxy = $array[$i];
echo "working on $i : <br/>";
echo "good to see you friend:".$currentProxy."<br/>";
$res1 = $memt1->get($currentProxy);
$res2 = $memt2->get($currentProxy);
echo "response for proxy:".$res1."<br/>";
echo "response for proxy:".$res2."<br/>";
if (!$res1){
echo "Does not exist - create<br/>";
$memt1->set($currentProxy, 1, null, 0);
} else {
echo "Does exist - help<br/>";
$memt1->increment($currentProxy);
}
if (!$res2){
echo "Does not exist - create<br/>";
$memt2->set($currentProxy, 1, null, 0);
} else {
echo "Does exist - help<br/>";
$memt2->increment($currentProxy);
}
}
The problem I am facing is that both memt1 and memt2 are referring to the same, for instance, if I increment <192.168.3.41:8013> for memt1, it also increment it for memt2, I think that this could be a very noob question, but I've just entered to PHP world and I don't know how to handle this at all, this is what I tried, if somebody could help me, please I would be really grateful. Thanks in advance.