Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error When Trying Test Script #29

Open
anton101101 opened this issue Aug 22, 2017 · 3 comments
Open

Error When Trying Test Script #29

anton101101 opened this issue Aug 22, 2017 · 3 comments

Comments

@anton101101
Copy link

anton101101 commented Aug 22, 2017

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...')
@boenrobot
Copy link
Member

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.

@anton101101
Copy link
Author

anton101101 commented Aug 22, 2017

@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
Copy link
Author

anton101101 commented Aug 22, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants