Net_RouterOS
Net_RouterOS copied to clipboard
loop() over multiple connections at once
Currently, Client::loop() only loops over a single connection - the one of the client object itself.
This method should be made static, and loop over all opened connections, which would make it far easier to use in scenarios where during the same PHP request, multiple connections to different routers are made at the same time.
Right now, the only way to somewhat effectively deal with those scenarios is to give loop() a timeout, and then execute the next connection's loop(), which is far from ideal, both in performance and in convenience.
Implementing this would not be trivial though, as it may require some refactoring on lower levels, and more than likely will require changes in PEAR2_Net_Transmitter too.
This is not a solution, just quick&dirty workaround which I'm using. Maybe it'll help others. PHP CURL:
`<?php require('db.php'); $mh = curl_multi_init(); $handles = array();
$db = new Db(); $sql = "SELECT ip FROM ".TAB_MONITORING.""; $result = $db -> select($sql); foreach($result as $give) { // create several requests $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://wispmon.nz/getData.php?host=".$give['ip']."");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_multi_add_handle($mh, $ch);
$handles[] = $ch;
}
// execute requests and poll periodically until all have completed $isRunning = null; do { curl_multi_exec($mh, $isRunning); usleep(250000); } while ($isRunning > 0);
// fetch output of each request $outputs = array(); for ($i = 0; $i < count($handles); $i++) { $outputs[$i] = trim(curl_multi_getcontent($handles[$i])); curl_multi_remove_handle($mh, $handles[$i]);
//print_r($outputs);
} ?>`