PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php (solved)

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php (solved)

Post by marcmerlin »

I've had cacti working for close to 10 years on linux/debian and upgraded it multiple times.
And then the php5 to php7 upgrade from hell happened (I'm not even going to go into php 7.0 vs 7.2 vs 7.3). I can't believe how terrible php has been handled this complete incompatible upgrade and forcing a flag day as opposed to supporting both versions side by side like perl or python.

Anyway, after this forced php7 upgrade (pulled by another package I had to upgrade), plenty of things broke, and I haven't been able to get cacti working since then.
I did just upgrade it to 1.2.7+ds1-1 as packaged by debian.

I still get this in my apache logs each time I open a cacti page:
[:error] [pid 31112] [client 173.11.111.145:42710] PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php:1639\nStack trace:\n#0 /usr/share/cacti/site/graph_json.php(158): rrdtool_function_graph(93, '0', Array)\n#1 {main}\n thrown in /usr/share/cacti/site/lib/rrd.php on line 1639, referer: https://graphs.merlins.org/graphs/graph ... hyper=true

I spent hours trying to fix this and getting mbstring working (which clearly is not default in php for reasons I don't understand).
gargamel:/etc/cacti# dpkggrep mbstring
php-mbstring install
php7.2-mbstring install
php7.3-mbstring install
gargamel:/etc/cacti# php --version
PHP 7.3.12-1 (cli) (built: Nov 28 2019 07:34:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.12-1, Copyright (c) 1999-2018, by Zend Technologies
gargamel:/etc/cacti# php -m | grep mbstring
mbstring

So, the module is there and looks installed/available, but still, cacti keeps erroring as if it weren't there.

What should I try next?

Thanks,
Marc
Last edited by marcmerlin on Tue Dec 10, 2019 10:44 pm, edited 1 time in total.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by netniV »

make sure that you have enabled the mbstring extensions under apache as well as under the php cli.

a2enmod should work for you on debian i believe.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by marcmerlin »

I understand what you're saying, but didn't the 2 commands I posted confirm that I'm using the correct php and that the module is enabled?

Repasting;

Code: Select all

gargamel:/etc/cacti# php --version
PHP 7.3.12-1 (cli) (built: Nov 28 2019 07:34:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.12-1, Copyright (c) 1999-2018, by Zend Technologies
gargamel:/etc/cacti# php -m | grep mbstring
mbstring
If php -m somehow isn't the correct way to validate this, please let me know what I may have missed.
Now that I'm forced to have 3 PHP versions on my server due to package dependencies, it's a complete mess. I think everything is running php 7.3 though.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by netniV »

No, that just confirms that the cli has it enabled.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by marcmerlin »

oh, the cli and apache php7 module handle modules separately? What madness is this? I already hated php, but now even more so :-/
Ok, I'll try and learn more about how php7 works and see how a2enmod works, thanks for the tip.
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by marcmerlin »

netniV wrote: Mon Dec 09, 2019 7:31 pm No, that just confirms that the cli has it enabled.
Ok, just had time to try; a2enmod is meant to enable an apache module, not a php module.

Code: Select all

gargamel:~# a2enmod
Your choices are: access_compat actions alias allowmethods asis auth_basic auth_digest auth_form authn_anon authn_core authn_dbd authn_dbm authn_file authn_socache authnz_fcgi authnz_ldap authz_core authz_dbd authz_dbm authz_groupfile authz_host authz_owner authz_user autoindex buffer cache cache_disk cache_socache cern_meta cgi cgid charset_lite data dav dav_fs dav_lock dbd deflate dialup dir dump_io echo env expires ext_filter file_cache filter headers heartbeat heartmonitor http2 ident imagemap include info lbmethod_bybusyness lbmethod_byrequests lbmethod_bytraffic lbmethod_heartbeat ldap log_debug log_forensic lua macro mime mime_magic mpm_event mpm_prefork mpm_worker negotiation perl php5 php7.0 proxy proxy_ajp proxy_balancer proxy_connect proxy_express proxy_fcgi proxy_fdpass proxy_ftp proxy_hcheck proxy_html proxy_http proxy_http2 proxy_scgi proxy_wstunnel ratelimit reflector remoteip reqtimeout request rewrite sed session session_cookie session_crypto session_dbd setenvif slotmem_plain slotmem_shm socache_dbm socache_memcache socache_shmcb speling ssl status substitute suexec unique_id userdir usertrack vhost_alias xml2enc
Which module(s) do you want to enable (wildcards ok)?
There is no mbstring in there given that mbstring is a php module, which I think I gave evidence is already enabled (from php -m), and not an apache module.
Am I missing something?
Thanks.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by netniV »

Sorry, my bad I was half asleep. I think the command is phpenmod not a2enmod. I know that you ran php -m, but debian has two different configurations for php, one for cli and one for web.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
idle
Cacti User
Posts: 77
Joined: Wed May 26, 2004 10:49 am
Location: Barcelona
Contact:

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by idle »

You can check php modules for apache using browser.
Make new php script with phpinfo() and open it via browser.
Like this:

Code: Select all

echo '<?php phpinfo() ?>' > /usr/share/cacti/site/i.php
And point your browser to https://graphs.merlins.org/graphs/i.php

upd.
Or you can check phpinfo via Cacti utilities. https://graphs.merlins.org/graphs/utili ... ab=phpinfo
Last edited by idle on Tue Dec 10, 2019 8:47 am, edited 1 time in total.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by netniV »

idle wrote: Tue Dec 10, 2019 8:41 am You can check php modules for apache using browser.
Make new php script with phpinfo() and open it via browser.
Like this:

Code: Select all

echo '<?php phpinfo() ?>' > /usr/share/cacti/site/i.php
And point your browser to https://graphs.merlins.org/graphs/i.php
That is actually a good recommendation, though do remember to remove it afterwards as it will contain potentially sensitive information.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by marcmerlin »

netniV wrote: Tue Dec 10, 2019 8:20 am Sorry, my bad I was half asleep. I think the command is phpenmod not a2enmod. I know that you ran php -m, but debian has two different configurations for php, one for cli and one for web.
Thanks for offering your help.

Clearly I know nothing about how php7 is supposed to work, and sadly it looks like debian did a poor job of just making it work (as in not the cacti package, but this php7 mess)

See below

Code: Select all

gargamel:~# phpenmod mbstring
WARNING: Module mbstring ini file doesn't exist under /etc/php/7.0/mods-available
WARNING: Module mbstring ini file doesn't exist under /etc/php/7.0/mods-available
WARNING: Module mbstring ini file doesn't exist under /etc/php/7.0/mods-available
gargamel:~# ln -s /usr/share/php7.3-mbstring/mbstring/mbstring.ini /etc/php/7.0/mods-available
gargamel:~# phpenmod mbstring
gargamel:~# 
And yet after that, it still doesn't work because it was the wrong phpenmod from an outdated php-common package that didn't get upgraded by php7.3 (it should have had a dependency).

Code: Select all

Unpacking php-common (2:69) over (1:57) ...
gargamel:~# phpdismod mbstring
gargamel:~# cat /etc/php/7.3/mods-available/mbstring.ini
; configuration for php mbstring module
; priority=20
extension=mbstring.so
gargamel:~# phpenmod mbstring
gargamel:/usr/share/cacti/site# phpquery -V
7.3
7.2
7.0
gargamel:~# find /etc/apache2/ |grep php |grep enabled
/etc/apache2/mods-enabled/php7.0.conf
/etc/apache2/mods-enabled/php7.0.load
gargamel:~# dpkg -S /usr/lib/apache2/modules/libphp7.0.so
libapache2-mod-php7.0: /usr/lib/apache2/modules/libphp7.0.so
gargamel:~# apt-get install libapache2-mod-php7.3
Creating config file /etc/php/7.3/apache2/php.ini with new version
libapache2-mod-php7.3: php7.0 module already enabled, not enabling PHP 7.3
gargamel:~# apt-get remove libapache2-mod-php7.0
not quite what I expected
1) php7.3 already had the module
2) php-common seems to default to 7.0 and ignore the 7.3 install although it also reports that all 3 are installed
3) installing php7.3 indeed only installed the command line stuff and not the apache module too, so I was running the wrong version.

After fixing all this, cacti finally works again (seems that it doesn't work with 7.0 even with mbstring installed, but it worked with 7.3 once I finally got it working in apache.

Thanks for the help.
Marc
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by marcmerlin »

Mmmh, I spoke too soon. It works better, but now errors on this when I look at a graph:

PHP Fatal error: Uncaught Error: Call to undefined function xml_parser_create() in /usr/share/cacti/site/lib/xml.php:112\nStack trace:\n#0 /usr/share/cacti/site/lib/rrd.php(2303): rrdxport2array('<?xml version="...')\n#1 /usr/share/cacti/site/lib/rrd.php(2321): rrdtool_function_graph(97, '0', Array, '', Array)\n#2 /usr/share/cacti/site/graph_xport.php(99): rrdtool_function_xport(97, '0', Array, Array)\n#3 {main}\n thrown in /usr/share/cacti/site/lib/xml.php on line 112
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by marcmerlin »

idle wrote: Tue Dec 10, 2019 8:41 am You can check php modules for apache using browser.
Make new php script with phpinfo() and open it via browser.
Like this:

Code: Select all

echo '<?php phpinfo() ?>' > /usr/share/cacti/site/i.php
And point your browser to https://graphs.merlins.org/graphs/i.php

upd.
Or you can check phpinfo via Cacti utilities. https://graphs.merlins.org/graphs/utili ... ab=phpinfo
So, I definitely have it working better now, but still has issues. You can look at
http://graphs.merlins.org/graphs/graph_ ... hyper=true
this works, until you click on a graph gear icon
Error: 500 Internal Server Error
Reason: The response to the last action was unexpected.

I'll send you a PM with the phpinfo output.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by netniV »

Error 500 means that there was an internal server error and you look to the apache error log to see why.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
marcmerlin
Cacti User
Posts: 86
Joined: Mon Oct 12, 2009 3:11 pm

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php

Post by marcmerlin »

netniV wrote: Tue Dec 10, 2019 9:01 pm Error 500 means that there was an internal server error and you look to the apache error log to see why.
I already did and already pasted the error logged in apache.log above :)

Code: Select all

PHP Fatal error: Uncaught Error: Call to undefined function xml_parser_create() in /usr/share/cacti/site/lib/xml.php:112\nStack trace:\n#0 /usr/share/cacti/site/lib/rrd.php(2303): rrdxport2array('<?xml version="...')\n#1 /usr/share/cacti/site/lib/rrd.php(2321): rrdtool_function_graph(97, '0', Array, '', Array)\n#2 /usr/share/cacti/site/graph_xport.php(99): rrdtool_function_xport(97, '0', Array, Array)\n#3 {main}\n thrown in /usr/share/cacti/site/lib/xml.php on line 112
Is that supposed to be part of core php, or yet another module that I'm missing? Mmmh, the real error was actually above in the logs. /var/lib/php/sessions was not writeable in the container, but the last erorr logged pointed me towards xml_parser_create which was not really the problem.

Code: Select all

[Tue Dec 10 19:31:27.093911 2019] [php7:warn] [pid 303] [client 173.11.111.145:54344] PHP Warning:  session_start(): open(/var/lib/php/sessions/sess_4pmoaqm9up35dkhcs7a8o4ua74, O_RDWR) failed: Read-only file system (30) in /usr/share/cacti/site/include/global.php on line 386, referer: http://graphs.merlins.org/graphs/graph_view.php?action=tree&node=tree_anchor-7&site_id=-1&host_id=-1&host_template_id=-1&hgd=&hyper=true
[Tue Dec 10 19:31:27.094120 2019] [php7:warn] [pid 303] [client 173.11.111.145:54344] PHP Warning:  session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /usr/share/cacti/site/include/global.php on line 386, referer: http://graphs.merlins.org/graphs/graph_view.php?action=tree&node=tree_anchor-7&site_id=-1&host_id=-1&host_template_id=-1&hgd=&hyper=true
Looks like I'm all good now, thanks for the help.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in /usr/share/cacti/site/lib/rrd.php (solve

Post by netniV »

Well, actually, that means you don't have the XML modules enabled, nor the session modules either. I would look at the full list of desired modules and then ensure that they have all been enabled under your newer php version for both cli and apache.

I had assumed that the above error had come from the cacti log files.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests