I have started with PHP API (topic http://forum.mikrotik.com/t/basic-help-with-php-api/30578/1), but wanted to keep same CLI syntax, what is not possible what I didn`t know at the beginning. Since I wanted to preserve original syntax, I have found SSH2 for php, and despite tricky installation, I was delighted how things going on. However, after executing any command without issue, naturally, now I wanna fetch output, but there is the problem. Here is the code:
// collect returning data from command original
stream_set_blocking( $stream, true );
$data = "";
while( $buf = fread($stream,4096) ){
$data .= $buf;
}
fclose($stream);
I have tried withoud while loop, but still nothing. Accidentally, I got the output from only this command:
/ip firewall filter print
presume because its larger amount of data or maybe it took a bit more time to fetch result...dont know, I have tried to “slow down” with sleep(1), but still nothing, any help would be really appreciated since this part is missing to start connect my php/mysql billing database with mikrotik network.
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