Cacti: Cacti 1.1.37 / PHP 7.2 / ERROR PHP WARNING: sizeof(): lib/utility.php

Created on 18 Apr 2018  路  16Comments  路  Source: Cacti/cacti

I ran in this bug with 1.1.37 when rebuilding poller cache from cli
ERROR PHP WARNING: sizeof(): Parameter must be an array or an object that implements Countable in file: /usr/share/cacti/lib/utility.php on line: 541
Looking more into it

 $ids = array();
(...)
                foreach($local_data_ids as $id) {
                        if ($count == 0) {
                                $ids = $id;
                        } else {
                                $ids .= ', ' . $id;
                        }
                        $count++;
                }
(...)
 if (sizeof($ids)) {

Most helpful comment

The fix for this appears to be:

diff --git a/lib/utility.php b/tmp/utility.php
index 6488d98..306e6e4 100644
--- a/lib/utility.php
+++ b/tmp/utility.php
@@ -459,7 +459,7 @@ function push_out_data_input_method($data_input_id) {
  */
 function poller_update_poller_cache_from_buffer($local_data_ids, &$poller_items) {
        /* set all fields present value to 0, to mark the outliers when we are all done */
-       $ids = array();
+       $ids = '';
        if (sizeof($local_data_ids)) {
                $count = 0;
                foreach($local_data_ids as $id) {
@@ -538,7 +538,7 @@ function poller_update_poller_cache_from_buffer($local_data_ids, &$poller_items)
        }

        /* remove stale records FROM the poller cache */
-       if (sizeof($ids)) {
+       if (strlen($ids)) {
                db_execute("DELETE FROM poller_item WHERE present=0 AND local_data_id IN ($ids)");
        } else {
                /* only handle explicitely given local_data_ids */

All 16 comments

The fix for this appears to be:

diff --git a/lib/utility.php b/tmp/utility.php
index 6488d98..306e6e4 100644
--- a/lib/utility.php
+++ b/tmp/utility.php
@@ -459,7 +459,7 @@ function push_out_data_input_method($data_input_id) {
  */
 function poller_update_poller_cache_from_buffer($local_data_ids, &$poller_items) {
        /* set all fields present value to 0, to mark the outliers when we are all done */
-       $ids = array();
+       $ids = '';
        if (sizeof($local_data_ids)) {
                $count = 0;
                foreach($local_data_ids as $id) {
@@ -538,7 +538,7 @@ function poller_update_poller_cache_from_buffer($local_data_ids, &$poller_items)
        }

        /* remove stale records FROM the poller cache */
-       if (sizeof($ids)) {
+       if (strlen($ids)) {
                db_execute("DELETE FROM poller_item WHERE present=0 AND local_data_id IN ($ids)");
        } else {
                /* only handle explicitely given local_data_ids */

Although I may switch that around and use a prepared statement instead.

Just looked at the 1.2 version and it already had the change from array to empty string but the sizeof was still incorrect. So I've submitted as a pull request. The above may be applicable to the 1.1.x releases.

Looks resolved to me.

Will 1.1.x never die. Need to accelerate the 1.2 stuff. Almost out of time this morning.

WOW ~ Thanks a lot ~

Hello Sir, Hope this form is still valid. Can you please check if I am facing the same problem? 2019/06/25 03:51:26 - CMDPHP PHP ERROR WARNING Backtrace: (/poller_commands.php: 112 run_data_query)(/lib/data_query.php: 154 update_poller_cache_from_query)(/lib/utility.php: 103 poller_update_poller_cache_from_buffer)(/lib/utility.php: 541 sizeof)(CactiErrorHandler)(/lib/functions.php: 4585 cacti_debug_backtrace)

time zone in php.ini is set to correct time zone but still cacti graphs are 1 day behind. any help would be really appreciated

Hard to say without knowing more information starting with what version you are on.

Just write a test script to preform a timezone get, that will tell you if the timezone is actually right. PHP can be difficult sometimes. You think you have the timezone right, only to find out that you needed a space here and there, or to remove quotes or convert an underscore to a space. It's all version dependent.

The current Ubuntu cacti package has not been fixed.

Can you be more specific?

I have just installed Cacti (Ubuntu package) on Ubuntu 18.04 and had this error in cacti.log, followed your fix which helped me with the poller issues. https://github.com/Cacti/cacti/issues/1546#issuecomment-382320908

Then I suspect your system only has old packages, what version are you on?

Yes, it looks like this is not the latest version.
https://packages.ubuntu.com/bionic/cacti

Ubuntu 18.04

Package: cacti
Architecture: all
Version: 1.1.38+ds1-1
Priority: extra
Section: universe/web
Origin: Ubuntu
Maintainer: Ubuntu Developers ubuntu-devel-discuss@lists.ubuntu.com
Original-Maintainer: Cacti Maintainer pkg-cacti-maint@lists.alioth.debian.org
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 11227
Depends: dbconfig-common (>= 2.0.9~), dbconfig-mysql | dbconfig-no-thanks, fonts-dejavu-core, fonts-dejavu-extra, fonts-font-awesome, javascript-common, libapache2-mod-php | php, libjs-c3, libjs-chartjs, libjs-d3, libjs-jquery (>= 1.10), libjs-jquery-cookie, libjs-jquery-hotkeys, libjs-jquery-metadata, libjs-jquery-tablesorter (>= 1:2.28.9+dfsg1~), libjs-jquery-timepicker, libjs-jquery-ui, libjs-jquery-ui-touch-punch, libphp-phpmailer, php-cli, php-gd, php-json, php-ldap, php-mbstring, php-mysql, php-php-gettext, php-phpseclib, php-snmp, php-twig, php-xml, rrdtool, snmp, ucf, debconf (>= 0.5) | debconf-2.0, libjs-jquery-colorpicker (>= 1.2.16), libjs-jquery-jstree (>= 3.3.5+dfsg1), libjs-jquery-ui-theme-smoothness (>= 1.12.1+dfsg), libjs-jquery-ui-theme-south-street (>= 1.12.1+dfsg), libjs-jquery-ui-theme-ui-darkness (>= 1.12.1+dfsg), perl:any
Recommends: apache2 | lighttpd | nginx | httpd, default-mysql-server | virtual-mysql-server, inetutils-ping | iputils-ping, logrotate, php-gmp
Suggests: cacti-spine, moreutils, snmpd
Filename: pool/universe/c/cacti/cacti_1.1.38+ds1-1_all.deb
Size: 3952140

1.2.2 is only for 19.04

Is it really not supported in 18.04?

The latest stable version is 1.2.7

Cacti sources work perfectly fine under 18.04 (I use that). However, the packages that the debian Cacti 1.2.x package depends on may only be available from 19.04

Was this page helpful?
0 / 5 - 0 ratings