What you’re doing is that for every iteration in your loop, you’re making a brand new connection, login to the router once again. This is a huge waste of resources.
Move the new RouterOS\Util and new RouterOS\Client outside of the loop, so that you keep using the same connection for all vouchers.
Also, you have two loops, with the “for” one not really serving its purpose. Remove it. You’re already making the 7500 check inside the foreach anyway… i.e. only the first 7500 lines in your file would result in vauchers.
Today morning I’ve upgraded my router to the latest stable version because I thought the problem with the router version, and now when I’m trying to connect to the router using API I’m getting a username or password error.
and I’m sure of the credentials are fine because i can log in through inbox.
Thank you very much and work with your script
so now i have new problem after added new profile, the billing/time left session will start and pause if any profile before and active in session.
maybe any script just add new profile without activated new profile (new profile will active after previous profile ended).
Hello,
I know this an old post. Please i need an assistance on this issue. I am building a database using my php. I want to use a script to add these users from the php database to Userman.
Through google and this forum, i have downloaded Infinitel Hotspot Auto service but to no avail. I have used pearl but to no avail.
see my script below
<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
//$db = mysqli_connect('localhost','root','','students');
$client = new RouterOS\Client('192.168.2.2', 'admin', 'password@1', '8728');
$mysqli = new mysqli('localhost', 'root', '', 'students');
$addRequest = new RouterOS\Request('/tool user-manager user add');
\
\
$users = $mysqli->query('SELECT `RegistrationID` AS `username`, `Lastname` AS `password` FROM `user`');
\
\
//die(var_dump($users->fetch_object()));
while ($user = $users->fetch_object()) {
$addRequest
->setArgument('name', $user->username)
->setArgument('password', $user->password)
->setArgument('customer', 'admin')
->setArgument('profile', 'staff');
$client($addRequest);
// var_dump($addRequest);
}
?>
i was modified every script in this forum for make this working. it was succed in the localhost. but didn’t working in the real host… i was user VPS as Userman Server…
Controller :
function __construct(){
parent::__construct();
require_once(APPPATH.'libraries/PEAR2/Autoload.php');
}
function edit(){
try {
$util = new PEAR2\Net\RouterOS\Util($client = new PEAR2\Net\RouterOS\Client('103.xxx.xxx.xxx', 'user', 'password'));
} catch (Exception $e) {
// redirect when failed
redirect(base_url().'admin/pelanggan/data?alert=gagal_konek_userman');
}
}`