jeanmarc77 / 123solar

123Solar is a lightweight set of PHP/JS files that makes a web logger to monitor your photovoltaic inverter(s). It just need a web server and PHP, no databases are even needed. The philosophy is: To keep it simple, fast, with a low foot print to run on cheap and low powered devices.
GNU General Public License v3.0
36 stars 12 forks source link

PHP8.0 Compatibility #22

Closed escix closed 2 years ago

escix commented 2 years ago

Hi, Is this code compatible with PHP8.0. I am getting lots of error with PHP8.0 where is was working fine with PHP7.2

jeanmarc77 commented 2 years ago

Sure, i run with PHP 8.1.8. What are the error ? Check hints into '[Help and debugger]'

escix commented 2 years ago

the script doesn't create the 123solar.pid file. Also I had the following errors: PHP Warning: Trying to access array offset on value of type null in...

Checking running softwares is also blank.

jeanmarc77 commented 2 years ago

What about admin/fperms.php ?

escix commented 2 years ago

All OK

jeanmarc77 commented 2 years ago

duh.. maybe enable debug, restart 123s, check also your webserver error log and send me more details

escix commented 2 years ago

I run 123Solar in FreeBSD, which I run before too but older version in Raspberry PI. Now moved to x64 thinclient and upgraded to latest version with PHP8.0. The reading works still, but the button in the admin panel stays off.

jeanmarc77 commented 2 years ago

do you have a ../scripts/123solar.pid file ? I guess not, that's the issue

escix commented 2 years ago

Now fixed the ps command in admin/help.php file for FreeBSD. Now the Running Softwares in the help.php shows the running processes.

The 123solar.pid file is not getting created when starting. not sure why?

jeanmarc77 commented 2 years ago

maybe the command is unappropriate for FreeBSD, in admin/admin.php line 118 : ps -ef | grep $PID | grep 123solar.php

escix commented 2 years ago

perfect, working now. Cheers

jeanmarc77 commented 2 years ago

what was the command ?

i guess scripts/distros/ commands are not good for FreeBSD. Mind checking them and make a new one ? I could set the PID command return different by setting distro in admin panel.

escix commented 2 years ago

ps -auxw to display all processes

jeanmarc77 commented 2 years ago

ok and what for $UPTIME= $CPUUSE= $MEMTOT= $MEMUSE= $MEMFREE= $DISKUSE= $DISKFREE

escix commented 2 years ago

Except $MEM* everything else works as expected. For memory info a pkg needs to beinstalled. I think it is memfree or freemem or similar. Sorry I forgot - which I don't have installed.

jeanmarc77 commented 2 years ago

ok, so tell me if you know. I work by implementing PID via distro thanks

escix commented 2 years ago

Could you use something like this:

sysctl -a | grep 'real memory' sysctl -a | grep 'avail memory'

jeanmarc77 commented 2 years ago

i've push on git, it will work on next stable update. Mind checking https://github.com/jeanmarc77/123solar/blob/main/scripts/distros/FreeBSD.php ?

escix commented 2 years ago

$CPUUSE="ps aux|awk 'NR > 0 { s +=$3 }; END {print \"cpu %\",s}' | awk '{ print $3 }'";

this doesn't work

error: awk: syntax error at source line 1 context is NR > 0 { s +=$3 }; END {print >>> \ <<< "cpu %\",s} awk: illegal statement at source line 1

jeanmarc77 commented 2 years ago

please provide the full working FreeBSD.php, i'll push it on git

escix commented 2 years ago

$CPUUSE="ps aux | awk 'NR > 2 { s +=$3 }; END {print "cpu %",s}' | awk '{print $3 }'"

escix commented 2 years ago

How does the distro files work? Does it automatically get the info or does it need to be modified in each php files?

for eg. in info.php there is this command which won't work in FreeBSD: cat /proc/cpuinfo | grep 'Processor' | head -n 1

same in admin.php as stated before.

jeanmarc77 commented 2 years ago

Not all commands are define there like cpuinfo, i can add them via distros files. It simply PHP exec the commands, just tell me what's work on BSD.

I've modify admin.php https://github.com/jeanmarc77/123solar/blob/main/admin/admin.php

escix commented 2 years ago

$CPUUSE="ps aux | awk 'NR > 0 { s +=$3 }; END {print "\cpu %",s}' | awk '{ print $3 }'";

When I use the above command i get the following error: FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected fully qualified name "\cpu" in

But it works on command line if I execute as user www.

% ps aux | awk 'NR > 0 { s +=$3 }; END {print "cpu %",s}' | awk '{ print $3 }' 0 %

jeanmarc77 commented 2 years ago

You miss a backslash, that's $CPUUSE="ps aux | awk 'NR > 0 { s +=$3 }; END {print "\cpu %\",s}' | awk '{ print $3 }'";

escix commented 2 years ago

I am getting an error when I put that backslash.

What should be the output from the above command? Is that just a number or cpu % 10 ?

jeanmarc77 commented 2 years ago

It should return a value like 25 which mean 25%

don't forget to remove the escape backslash if in CLI ps aux|awk 'NR > 0 { s +=$3 }; END {print "cpu %",s}' | awk '{ print $3 }'

escix commented 2 years ago

the one in the Ubuntu works.

Does it only shows the cpuuse for 123solar or for all processes?

escix commented 2 years ago

That's it I was checking in the CLI and not working, but it was working in the web

jeanmarc77 commented 2 years ago

It's total CPU usage like you can see via top.

CPU/men usage of 123s is seen on help page, lines 47 & 48 $cpu = exec("ps -p $PID -o %cpu | tail -1 | awk '{print $1}'"); $mem = exec("ps -p $PID -o %mem | tail -1 | awk '{print $1}'"); It is particularly low actually :)

escix commented 2 years ago

yes you are correct. It is the cpuuse by www user.

jeanmarc77 commented 2 years ago

sorry won't work as 123 do exec($CPUUSE); you shall return the value in one command