nadrad / h-m-m

Hackers Mind Map
GNU General Public License v3.0
1.89k stars 53 forks source link

I tried running the file using "php h-m-m.php" but it didn't work... just literally did nothing. I'm using linux. maybe you know what's the problem? #1

Closed hananelroe closed 2 years ago

nadrad commented 2 years ago

So, what happens when you run it, do you get any errors, does it freeze, or just return to the command line without doing anything? Which terminal emulator are you using?

hananelroe commented 2 years ago

no errors, just returns to command line. what do you mean by "terminal emulator"? I'm using what came with my POP!_OS installation...

nadrad commented 2 years ago

You probably search for "terminal" in your list of applications and run it to access the command line. The application you run this way is a "terminal emulator".

Open one terminal and run the following inside it: journalctl -f -g php

It shows you the latest logs that contain "php". Now open a second terminal and run the following: php -d log_errors=true h-m-m

(replace "h-m-m" with the new name if you've renamed the application.) The "-d log_errors=true" switch overrides your local settings, in case logging is disabled. Now check the first terminal and see if there's any errors and share them here.

hananelroe commented 2 years ago

no new errors when running it

nadrad commented 2 years ago

That's strange!

Do you mind installing another terminal emulator such as xfce-terminal or gnome-terminal and check to see if it works there?

Also, check your php version with php -v and let me know. I have 8.1 in my system. I think it should work with older php versions, in case that's what you have, but I can check to be sure.

felipelalli commented 2 years ago

The same issue here! No error, no log, just do nothing. PHP 7.4.28, terminal zsh.

bheadmaster commented 2 years ago

Same thing here. I'm running:

I've added some debug echos on my fork: https://github.com/bheadmaster/h-m-m/commit/c8a2bff5a5ca22bcd869bd9aaa64b7482c66bcb6

It seems that the script exits during the execution of the set_up_screen() function - all I see is this:

$ php -d log_errors=true ./h-m-m 
Setting up screen...
$

I'll try to debug further, but I just wanted to give you this info for now.

nadrad commented 2 years ago

Thanks @bheadmaster for digging into it. It works in my Konsole, so, I'm going to install Ubuntu and php 7 in a virtual machine and see what's going on there. Meanwhile, maybe you can comment everything in the set_up_screen function to see whether it works without it in your setup.

bheadmaster commented 2 years ago

Actually, the log is incomplete. I've noticed you call some stty functions which change the terminal state, basically destroying all "echo" output - which is why only the first echo, before set_up_screen(), printed any output.

I set up a file logging mechanism (https://github.com/bheadmaster/h-m-m/commit/67a06737ba37c7d4d60cc1c8fc36dff2160d1a42) and executed the script. Here's the log:

Setting up screen...
Calling stty...
Disabling text cursor and getting rid of mouse...
Setting up screen - DONE
Loading settings...
Clearing...
Loading file...
Collapsing all...

So it seems that the real culprit is actually the collapse_all($mm) function call.

I'm investigating further, will report any new findings.

bheadmaster commented 2 years ago

Okay, I've set up some more logs, and it seems that the real (for real this time!) culprit is actually the calculate_x_and_lh function.

Here's the file I've executed (with highlighted line which logs last): https://github.com/bheadmaster/h-m-m/blob/8aa07def707f56cda2cc48baba8ef92121b49ec7/h-m-m#L430

Here's output I get when I run this file, before it crashes:

Setting up screen...
Calling stty...
Disabling text cursor and getting rid of mouse...
Setting up screen - DONE
Loading settings...
Clearing...
Loading file...
Collapsing all...
calling foreach...
calling foreach - DONE
building map...
resetting the global values...
resetting the global values - DONE
executing foreach...
executing foreach - DONE
setting up some node stuff...
setting up some node stuff - DONE
calculating new coordinates...
calculating x and lh - 1...
calculating x and lh - 2...
calculating x and lh - 3...

Unfortunately, I couldn't figure out what's the real cause of the issue. I'll try a bit more, but can't promise anything. Hopefully these logs help you figure out what's wrong.

Wojciechem commented 2 years ago

@hananelroe @bheadmaster I suspect your php installations don't have pcntl extension enabled and configuration prevents you from seeing the error.

Please check for confirmation: php -m | grep pcntl php -i | grep error

nadrad commented 2 years ago

Thanks a lot, and well done figuring out that the extra echo's are lost in the alternate buffer. I got busy with something else and just got back to start setting up an Ubuntu machine. Where your logs have stopped are very unexpected! It may be a good idea to try this: create a file with a few lines of text and open it with h-m-m, to change those calculations and see if something changes.

bheadmaster commented 2 years ago

@Wojciechem Probably. I have zero experience in PHP, so I'm just throwing stuff at the wall until it sticks here :)

Here's the output you asked for:

$ php -m | grep pcntl
pcntl
$ php -i | grep error
display_errors => Off => Off
display_startup_errors => Off => Off
error_append_string => no value => no value
error_log => no value => no value
error_prepend_string => no value => no value
error_reporting => 22527 => 22527
html_errors => Off => Off
ignore_repeated_errors => Off => Off
log_errors => On => On
log_errors_max_len => 1024 => 1024
track_errors => Off => Off
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
opcache.error_log => no value => no value

Please do tell if there's anything that this output tells you.

@nadrad What do you mean by "open it with h-m-m"? Does "h-m-m" accept command line argument?

Something like ./h-m-m $FILENAME?


Anyways, I've investigated further - it was suspicious to me that the line calculating x and lh - 3... is printed, but not calculating x and lh - 3.1... nor calculating x and lh - 3.5... - as if the program didn't enter the if/else condition at all. That would mean that the computation inside the if was failing.

And it was!

For some reason, calling mb_strlen($node['title']) crashes the script. Here's the line: https://github.com/bheadmaster/h-m-m/blob/17b5d8f661e81788b9060e73efe16ad91e98eb6d/h-m-m#L446

Here's the log I get when I execute the above linked script:

Setting up screen...
Calling stty...
Disabling text cursor and getting rid of mouse...
Setting up screen - DONE
Loading settings...
Clearing...
Loading file...
Collapsing all...
calling foreach...
calling foreach - DONE
building map...
resetting the global values...
resetting the global values - DONE
executing foreach...
executing foreach - DONE
setting up some node stuff...
setting up some node stuff - DONE
calculating new coordinates...
calculating x and lh - 1...
calculating x and lh - 2...
calculating x and lh - 3...
evaluating node title...
evaluating node title - DONE
evaluating width tolerance times max width...
evaluating width tolerance times max width - DONE
getting type of node title...
string
getting type of node title - DONE
evaluating mb strlen of node title...

So mb_strlen($node['title']) fails. Anyone have any idea why?

I've checked the type of variable - gettype($node['title']) returns string.

Weird. But that's all I have.

Wojciechem commented 2 years ago

@bheadmaster Oh, so you do have pcntl, but lack mbstring! On Ubuntu, that'll probably be apt install php-mbstring :)

Errors are probably somewhere in /var/log/php7.4-cli.error.log

bheadmaster commented 2 years ago

I've installed php-mbstring and the original script works now. Thanks @Wojciechem !

Thanks @nadrad ! You might want to add a section in README.md that says that php-mbstring is a dependency. That'd probably prevent any further bug reports on this topic :)

saltzm commented 2 years ago

I had the same issue and after installing php-mbstring it at least opens and shows 'root', but as soon as I press 'o' or 'enter' it exits

nadrad commented 2 years ago

Someone has left this comment in Hacker News:

sudo apt install php7.4-mbstring # Fixed it. There's also package php-mbstring

It's compatible with what @bheadmaster has traced. Can you check and let us know?

bheadmaster commented 2 years ago

@saltzm Try to comment out line 164:

// system('stty cbreak -echo -crterase intr undef && tput smcup');      // production

And the content of the function clear on line 173:

function clear()       { /* echo "\033[2J"; */ }

Then re-run the script. You will most likely get a stack trace or an error.

saltzm commented 2 years ago

I had php 7.2, upgrading to 7.4 fixed it. Thanks!

nadrad commented 2 years ago

@bheadmaster , @Wojciechem , and everyone else, thanks a lot :) I'll add it to the readme for others.

And, by the way, @bheadmaster , yes, you can run h-m-m filename to open an existing file.