Cacti / plugin_flowview

FlowView Plugin for Cacti
GNU General Public License v2.0
17 stars 9 forks source link

ERROR PHP DEPRECATED in flow_collector.php with php 8.x (at least with 8.2) #95

Closed arno-st closed 1 week ago

arno-st commented 1 month ago

I'm stuck with this one! I have cacti 1.2.26, flowview from develop branch. And this function give me some trouble to solve:

Inside flow_collector.php line 424, and 425

$start_time = date('Y-m-d H:i:s.v', $flowtime + $rstime) . '.' . $rsmsec;
$end_time   = date('Y-m-d H:i:s.v', $flowtime + $retime) . '.' . $remsec;

Also with line 728 and 730 (inside get_sql_prefix)

$suffix = date('Y', $flowtime) . substr('000' . date('z', $flowtime), -3);
...
$suffix = date('Y', $flowtime) . substr('000' . date('z', $flowtime), -3) . date('H', $flowtime);

I got this error in the log

18/04/2024  15:42:55 - CMDPHP PHP ERROR Backtrace:   (/plugins/flowview/flow_collector.php[346]:process_fv5(),  /plugins/flowview/flow_collector.php[427]:get_sql_prefix(),  /plugins/flowview/flow_collector.php[728]:date(), CactiErrorHandler())
18/04/2024 15:42:55 - ERROR PHP DEPRECATED in  Plugin 'flowview':  Implicit conversion from float 1713448655.942916 to int loses precision  in file: /usr/share/cacti/plugins/flowview/flow_collector.php  on line:  728
18/04/2024 15:42:55 - CMDPHP PHP ERROR Backtrace:   (/plugins/flowview/flow_collector.php[346]:process_fv5(),  /plugins/flowview/flow_collector.php[427]:get_sql_prefix(),  /plugins/flowview/flow_collector.php[728]:date(), CactiErrorHandler())
18/04/2024 15:42:55 - ERROR PHP DEPRECATED in  Plugin 'flowview':  Implicit conversion from float 1713448655.942916 to int loses precision  in file: /usr/share/cacti/plugins/flowview/flow_collector.php  on line:  728
18/04/2024 15:42:55 - CMDPHP PHP ERROR Backtrace:   (/plugins/flowview/flow_collector.php[346]:process_fv5(),  /plugins/flowview/flow_collector.php[425]:date(), CactiErrorHandler())
18/04/2024 15:42:55 - ERROR PHP DEPRECATED in  Plugin 'flowview':  Implicit conversion from float 1713448646.9149158 to int loses precision  in file: /usr/share/cacti/plugins/flowview/flow_collector.php  on line:  425
18/04/2024 15:42:55 - CMDPHP PHP ERROR Backtrace:   (/plugins/flowview/flow_collector.php[346]:process_fv5(),  /plugins/flowview/flow_collector.php[424]:date(), CactiErrorHandler())
18/04/2024 15:42:55 - ERROR PHP DEPRECATED in  Plugin 'flowview':  Implicit conversion from float 1713448646.9149158 to int loses precision  in file: /usr/share/cacti/plugins/flowview/flow_collector.php  on line:  424

For the get_sql_prefix, I change the call on line 427 from:

        $sql_prefix = get_sql_prefix($flowtime);

To

        $sql_prefix = get_sql_prefix((int)$flowtime);

And it solve this issue ( we just need the year, day and hour, so an int value is ok):

18/04/2024 15:42:55 - CMDPHP PHP ERROR Backtrace:   (/plugins/flowview/flow_collector.php[346]:process_fv5(),  /plugins/flowview/flow_collector.php[427]:get_sql_prefix(),  /plugins/flowview/flow_collector.php[728]:date(), CactiErrorHandler())
18/04/2024 15:42:55 - ERROR PHP DEPRECATED in  Plugin 'flowview':  Implicit conversion from float 1713448655.942916 to int loses precision  in file: /usr/share/cacti/plugins/flowview/flow_collector.php  on line:  728

But for the 2 line 424 and 425, I'm can't understand how to solve it.

TheWitness commented 1 month ago

It's the php group screwing up again and declaring that date must use an integer when they worked fine with a float forever. They keep doing stupid things. So, for flowview we have to write a flowview_date() function or use the updated class instead.

Check out php.net and search for the date function. The red section says it all.

TheWitness commented 1 week ago

This is fixed now. IPFIX is also fixed. It was horribly broken.

arno-st commented 1 week ago

In this error it was also, and mainly relarted to the change on the function date, who whas not accepting anymore a float value, but only an int.

I didn't have time, yet, to look into it, but it's still open.