Community discussions

 
welitonxd
just joined
Topic Author
Posts: 5
Joined: Sun Jul 08, 2018 5:53 am

Script for show PPPoE Clients in Google MAP (PROBLEM SLOW)  [SOLVED]

Fri Aug 24, 2018 5:49 am

So, its my Script to search all clients PPPoE in an table on MySQL, for take the name, latitude, longitude, login and put in the XML code above, in the same script he verify if the client is online with api and populate another line. WORKS with an 30 clients in database, but stay very slow, when i increase this database, actually 300 clients, i have to increase the maximum execution time in php.ini to finish the process.

NEEDING SOMEONE TO ANALYZE AND SHOW ME BETTER WAY TO MAKE THE SAME THING, DECREASING THE TIME.

Code: Select all

<?php

session_start();
require_once('api_mt_include2.php');
$Server =$_SESSION['api_ip'];
$Username =$_SESSION['api_user'];
$Pass =$_SESSION['api_pass'];
$Port =$_SESSION['api_port'];
$www_port =$_SESSION['www_port'];

function ValidChar($cadena){// valida nombre secret
if (preg_match("/^([0-9a-zA-Z\@.]){1,36}$/", $cadena,$resultado)){
return true;
}else{
return false;
}
}
?>
<?php
require("config.php");

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&apos;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

// Opens a connection to a mySQL server
$connection=mysql_connect ($server, $user, $pass);
if (!$connection) {
die('Not connected : ' . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($db, $connection); //
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM mt_gen_pppoe"; // pesquisa todo mundo ||||||||||||||||(ainda nao )que estiver cadastrado com a localização
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

echo "<online>\n"; // cria o XML de CLIENTES ONLINE
$a=0;

// Iterate through the rows, printing XML nodes for each
while ($row1 = @mysql_fetch_assoc($result)){

$a++;
$login=$row1['login'];
$lat=$row1['gpslat'];
$lng=$row1['gpslng'];
$nomecliente=$row1['nome'];



if (ValidChar($login)==1) {
$name = $login;
$API = new routeros_api();
$API->debug = false;
if ($API->connect($Server , $Username , $Pass, $Port)) {
$API->write("/ppp/active/getall",false);
$API->write('?name='.$name,true);
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);
if(count($ARRAY)>0){ // RETORNA OS ONLINE

$active_uptime = $ARRAY[0]["uptime"];
$active_address = $ARRAY[0]["address"];
$active_name = $ARRAY[0]["name"];

echo "<username login='$active_name' nome='$nomecliente' lat='$lat' lng='$lng' icone='O' "; //CONECTADO VERDE ICONE 0 //PREENCHE aLINHA XML
$API->disconnect();
}
else{
echo "<username login='$login' nome='$nomecliente' lat='$lat' lng='$lng' icone='F' ";//DESCONECTADO VERMELHO ICONE F
}
}
}

echo "/>\n"; //Fecha a linha do XML
}

echo "</online>"; //FECHA o XML


?>

Who is online

Users browsing this forum: No registered users and 11 guests