ok nearly 12 years later... but as we know.. the PHP api stopped working on the latest versions of Mikrotik 6.4xx so why not use ssh2_connect in order to send cmds and fetch the output result from mikrotik
1st you need to have a server machine the first cmd will depend on your linux distro version, i am using linux-debian distros so this is the cmd in order to install the correct libraries
apt-get install php-ssh2
once installed you can start working on your connections
you need to create a connection script example: connect-mkt.php and add the code below
<?php
$methods = array('kex' => 'diffie-hellman-group1-sha1');
$connection = ssh2_connect('IP-OF-YOUR-MIKROTIK', PORT, $methods);
if ($connection) {
//echo "connection established\n\n";
if (ssh2_auth_password($connection, 'mikrotik-username', 'mikrotik-password')) {
sleep(2);
fclose($s);
}
else {
echo "connection failed, please check your login credentials\n";
}
}
?>
2nd you will need to create your PHP page flavour with your cmds exec and readout function you can use test php page like the one below
[quote]
<?php
include_once("connect-mkt.php");
$s = ssh2_exec($connection, '/system health gauges print');
stream_set_blocking($s,true);
$stream_out = ssh2_fetch_stream($s, SSH2_STREAM_STDIO);
//echo stream_get_contents($stream_out);
$output1 = stream_get_contents($stream_out);
echo "<pre>{$output1}</pre>";
sleep(2);
$s = ssh2_exec($connection, '/system identity print');
stream_set_blocking($s,true);
$stream_out = ssh2_fetch_stream($s, SSH2_STREAM_STDIO);
//echo stream_get_contents($stream_out);
$output2 = stream_get_contents($stream_out);
echo "<pre>{$output2}</pre>";
sleep(2);
$s = ssh2_exec($connection, '/system clock print');
stream_set_blocking($s,true);
$stream_out = ssh2_fetch_stream($s, SSH2_STREAM_STDIO);
//echo stream_get_contents($stream_out);
$output3 = stream_get_contents($stream_out);
echo "<pre>{$output3}</pre>";
sleep(2);
$s = ssh2_exec($connection, '/system routerboard print');
stream_set_blocking($s,true);
$stream_out = ssh2_fetch_stream($s, SSH2_STREAM_STDIO);
//echo stream_get_contents($stream_out);
$output4 = stream_get_contents($stream_out);
echo "<pre>{$output4}</pre>";
sleep(2);
fclose($s);
?>
[/quote]
3rd if you wish to output the result on a html form table or row.. you just need to use the code below inside your html form or table
[quote]
value="<?php echo "{$output1}";?>
value="<?php echo "{$output2}";?>
value="<?php echo "{$output3}";?>
value="<?php echo "{$output4}";?>
[/quote]