PHP API works only from terminal

Hi,
I tried this simple php code to check if API works correctly but if I run this code from terminal it shows me the log as requested instead with a browser it results in a blank page.

<?php use PEAR2\Net\RouterOS; require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar'; try { $util = new RouterOS\Util($client = new RouterOS\Client('192.168.2.1', 'xxx', 'xxx')); foreach ($util->setMenu('/log')->getAll() as $entry) { echo $entry('time') . ' ' . $entry('topics') . ' ' . $entry('message') . "\n"; } } catch (Exception $e) { echo 'Unable to connect to RouterOS.'; } ?>

A blank page? Odd… I would’ve expected a “Can’t connect to RouterOS message” at worst (at which point, your firewall would be the culprit, for sure).

What’s the PHP version used inside the browser? I’m thinking your web server might be using a different one from the one in terminal. And if that version is earlier than 5.3.0, it would produce a parse error, which would in turn cause a blank screen.

You can check your PHP version by commenting out the whole code (minus the “<?php" and "?>”), and just add “phpinfo();” to see what it would say at the top.

I’ve the same version in browser and in terminal.

browser: PHP Version 5.6.14-0+deb8u1

terminal: php -i
phpinfo()
PHP Version => 5.6.14-0+deb8u1

If I restart apache it works 1 time.
Do you know why?

That sounds even weirder.

I haven’t tested on any Linux variants (I test just on Windows), but I know of nothing that would possibly cause such a thing, and I’ve never had anyone report something like this before.

Maybe turn on error display/logging? See what shows up the second time around.

One way to dodge the problem would be to use CGI instead of FCGI or Apache module (whichever one you’re using right now), but that’s bad for performance, and wouldn’t fix the real problem.

Found the problem
https://xcache.lighttpd.net/ticket/273

I resolved uninstalling php5-xcache.
Last question: could you tell me how to list the setMenu possibilities?

You can’t…

Not unless MikroTik implement this feature request or something similar.

Right now, you can only look from terminal, and write that same thing… But that’s doing it manually. Programmatically, the only possibility is to analyze SSH output, which can be somewhat error prone, not to mention not trivial.

Oh, and BTW, if you do want/need to get XCache back, then instead of using the PHAR file, you could extract the TGZ file, and include the “src/PEAR2/Autoload.php” file. This XCache issue appears to only affect PHAR files, so this alternative approach should work fine.

Thanks, I will try.