MTS icon indicating copy to clipboard operation
MTS copied to clipboard

Call to a member function getPathAsString() on boolean

Open ostrolucky opened this issue 7 years ago • 6 comments

using your example code

$shellObj = \MTS\Factories::getDevices()->getRemoteHost('ip_address')->setConnectionDetail('username', 'password')->getShell();

results in

$ php index.php
PHP Fatal error:  Uncaught Error: Call to a member function getPathAsString() on boolean in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Local/Host/Shell.php:67
Stack trace:
#0 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Local/Host/Shell.php(16): MTS\Common\Devices\Actions\Local\Host\Shell->execute()
#1 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Types/Localhost.php(55): MTS\Common\Devices\Actions\Local\Host\Shell->getShell('bash', false, false, 1000, 1000)
#2 /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Types/Remotehost.php(66): MTS\Common\Devices\Types\Localhost->getShell('bash', false)
#3 /home/g9735/IdeaProjects/mts/index.php(5): MTS\Common\Devices\Types\Remotehost->getShell()
#4 {main}
  thrown in /home/g9735/IdeaProjects/mts/MTS/Common/Devices/Actions/Local/Host/Shell.php on line 67

ostrolucky avatar Oct 13 '18 12:10 ostrolucky

You do not have screen installed. And I have a validation that is incorrect when checking for it.

merlinthemagic avatar Oct 13 '18 13:10 merlinthemagic

I've also encountered this issue, but not with screen, but with python executable. It's because on Ubuntu 20.04+ there is no python executable. Only python3.

The problem is that it's hardcoded here: https://github.com/merlinthemagic/MTS/blob/4df3b1283dfd6a7a7176442b4751fb126873edfc/MTS/Common/Devices/Actions/Local/Host/Shell.php#L51

Can you make this configurable? Through static property or some other suitable way?

mskocik avatar Jan 06 '24 15:01 mskocik

@mskocik May i suggest you give MTM-SSH a shot (or just the basic shells lib if you dont need remote ). Its maintained and has far better performance than MTS and the API is almost the same.

Edit: Python3 also became the preferred binary about 2 weeks ago

merlinthemagic avatar Jan 08 '24 21:01 merlinthemagic

So what's the difference between MTS and MTM-shells? (I don't need remote) Is MTM-shells just new version of the concept being implemented in MTS and extracted to separate package?

I will try to switch MTM-shells later. Code is already in production.

Btw when I was checking repos, MTS had feeling of being more stable - it has some version released, more detailed documentation.

mskocik avatar Jan 10 '24 08:01 mskocik

Hi @mskocik ,

MTS is going on 8 years and it does not lend itself well to applications where a single PHP process runs multiple shells. Mostly because each command and subsequent reading of the return is executed sync. This is solved in MTM-Shells with command objects that allows this flow to be broken up with a call to execute the command (exec()), but read the return later (get()).

Second, MTS relies on "screen" for local shells, that is quite a bit of extra complexity that is no longer needed. In MTM-Shells each shell is just a python process spawned with PTY and a set of pipes for control. Much cleaner execution and tear down.

Third, the structure of MTS was poorly conceived as it proved hard to extend to new shell types and terminals. Obvs, if all you need is bash then who cares, but since the shells lib also form the base for remote shells (e.g. MTM-SSH) it became important to break each type out on its own, allowing for completely separate return data parsing / execution structure etc.

Lastly, MTS has bolted on PhantomJS which was abandoned when Chrome got headless execution. That is quite a bit of code base that really should be ripped out, but who find that kind of time. Its also too much of a monolith with its own file objects and utilities, those also needed to be broken out.

All in all, it seemed like a good time for a re-write and hence MTM-Shells.

If you stick with MTS keep an eye on used file handles and abandoned python processes. There is a bug somewhere that stops shells from being torn down and leaves them running indefinitely and abandoned. Its not common, but if it happens in your use case it leads to some irritating resource exhaustion scenarios.

merlinthemagic avatar Jan 10 '24 11:01 merlinthemagic

@merlinthemagic just stopping by to say, I migrated to MTM-Shells as you recommended 👍🙏. There was no other way, because of deprecation warning (using php8.1 with enabled error reporting for deprecations)

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/platform3/vendor/merlinthemagic/mts/MTS/Common/Devices/Shells/Bash.php:66

mskocik avatar Feb 01 '24 14:02 mskocik