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

Call to a member function getPathAsString() on boolean #42

Open
ostrolucky opened this issue Oct 13, 2018 · 6 comments
Open

Call to a member function getPathAsString() on boolean #42

ostrolucky opened this issue Oct 13, 2018 · 6 comments
Assignees

Comments

@ostrolucky
Copy link

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
@merlinthemagic
Copy link
Owner

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

@mskocik
Copy link

mskocik commented Jan 6, 2024

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:

$pythonExe = \MTS\Factories::getActions()->getLocalApplicationPaths()->getExecutionFile('python');

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

@merlinthemagic
Copy link
Owner

merlinthemagic commented Jan 8, 2024

@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

@mskocik
Copy link

mskocik commented Jan 10, 2024

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.

@merlinthemagic
Copy link
Owner

merlinthemagic commented Jan 10, 2024

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.

@mskocik
Copy link

mskocik commented Feb 1, 2024

@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

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

No branches or pull requests

3 participants