Net_RouterOS icon indicating copy to clipboard operation
Net_RouterOS copied to clipboard

Error When Trying Test Script

Open anton101101 opened this issue 8 years ago • 3 comments
trafficstars

Hi,

Looking for some help please, when I run the test php script (below) from the CLI I get some errors (below) which I can't seem to find any reports of from a google search or on here and cant figure what's going wrong.

Any help is appreciated.

Thanks

PHP Script

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b6.phar';

try {
    $client = new RouterOS\Client('192.168.88.1', 'apiuser', 'example');
    echo 'OK';
} catch (Exception $e) {
    die($e);
}

?>

Error

exception 'Exception' with message 'Class PEAR2\Net\RouterOS\Client could not be loaded from PEAR2/Net/RouterOS/Client.php, file does not exist (registered paths="phar:///root/PEAR2_Net_RouterOS-1.0.0b6.phar/PEAR2_Net_RouterOS-1.0.0b6/src") [PEAR2_Autoload-@PACKAGE_VERSION@]' in phar:///root/PEAR2_Net_RouterOS-1.0.0b6.phar/PEAR2_Net_RouterOS-1.0.0b6/src/PEAR2/Autoload.php:305
Stack trace:
#0 [internal function]: PEAR2\Autoload::load('PEAR2\\Net\\Route...')
#1 /root/index.php(7): spl_autoload_call('PEAR2\\Net\\Route...')

anton101101 avatar Aug 22 '17 11:08 anton101101

Let me guess... Ubuntu 16.04? That particular Ubuntu version keeps throwing stupid stuff like this... 16.10 and later are fine, just this one.

The problem is with the bundled PEAR2\Autoload... A fix is already in its master branch, but not only is there not a release yet, that doesn't change the fact the bundled PEAR2\Autoload has this issue.

You have two possible workarounds:

  1. Upgrade to a newer Ubuntu version with sudo do-release-upgrade
  2. Extract the PHAR file (the issue only happens with PHAR files, not with "plain" files) or download and extract either the zip or tgz archive. Either way, extract it, and include src/PEAR2/Autoload.php.

boenrobot avatar Aug 22 '17 11:08 boenrobot

@boenrobot

Found your post in https://forum.mikrotik.com/viewtopic.php?t=101560 for the workaround.

So got around the problem by extracting the PHAR file using the command phar extract -f PEAR2_Net_RouterOS-1.0.0b6.phar

Then using require_once 'PEAR2_Net_RouterOS-1.0.0b6/src/PEAR2/Autoload.php'; in the script instead.

Thanks

anton101101 avatar Aug 22 '17 11:08 anton101101

FYI for the above I created a brand new Virtual Machine for this which wasn't 16.04.

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty

PHP 5.6.31-4+ubuntu14.04.1+deb.sury.org+4 (cli) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

anton101101 avatar Aug 22 '17 11:08 anton101101