1

I've got a project on an Ubutu server. I keep getting the following error

\FatalThrowableError: Call to undefined function bandwidthThrottle\tokenBucket\util\bcsub()
in vendor/bandwidth-throttle/token-bucket/classes/util/TokenConverter.php:80


 public function convertMicrotimeToTokens($microtime)
    {
        $delta = bcsub(microtime(true), $microtime, $this->bcScale); // <--- this line
        return $this->convertSecondsToTokens($delta);
    }

The package we're using is the bandwidth-throttle/token-bucket and we're using 2.0

I've made sure that bcmath is installed across each version of php on the server

I Ran the following;

sudo apt-get install php7.1-bcmath
sudo apt-get install php7.2-bcmath
sudo apt-get install php7.3-bcmath
sudo apt-get install php7.4-bcmath

sudo service apache2 restart

When I run "php -r "print_r(get_loaded_extensions());"" I get the following so I know it's there but my project is throwing an error anyway

Array
(
    [0] => Core
    [1] => date
    [2] => libxml
    [3] => openssl
    [4] => pcre
    [5] => zlib
    [6] => filter
    [7] => hash
    [8] => pcntl
    [9] => Reflection
    [10] => SPL
    [11] => session
    [12] => standard
    [13] => sodium
    [14] => mysqlnd
    [15] => PDO
    [16] => xml
    [17] => bcmath
    [18] => calendar
    [19] => ctype
    [20] => curl
    [21] => dom
    [22] => mbstring
    [23] => FFI
    [24] => fileinfo
    [25] => ftp
    [26] => gd
    [27] => gettext
    [28] => iconv
    [29] => json
    [30] => ldap
    [31] => exif
    [32] => mysqli
    [33] => pdo_mysql
    [34] => pdo_pgsql
    [35] => pgsql
    [36] => Phar
    [37] => posix
    [38] => readline
    [39] => shmop
    [40] => SimpleXML
    [41] => sockets
    [42] => sysvmsg
    [43] => sysvsem
    [44] => sysvshm
    [45] => tokenizer
    [46] => xmlreader
    [47] => xmlwriter
    [48] => xsl
    [49] => Zend OPcache
)

I also ran print_r(get_loaded_extensions()); within the webserver context (as in: fetching this through a browser, not on the shell)

...
[13] => apache2handler 
[14] => mysqlnd 
[15] => PDO 
[16] => xml 
[17] => bcmath <-------
[18] => calendar 
[19] => ctype 
...

Any sugguestions?

-- Edit

I've now found that the set php version is 7.2 and I know where the php.ini is

GingerFish
  • 457
  • 3
  • 11
  • 26
  • 1
    The error is not because of the missing PHP `bcsub()`, it just says already, it can't find the method `bcsub()` in `bandwidthThrottle\tokenBucket\util`! – CodyKL Feb 11 '20 at 10:00
  • 1
    And to get the running PHP version in browser you can use the function `phpversion()` – CodyKL Feb 11 '20 at 10:01
  • @CodyKL how can I force the package to use the PHP version of bcsub then? When looking at this on my local (not on the server) it's using the php bcsub not the package's. – GingerFish Feb 11 '20 at 10:57
  • The question is first in which file is this error thrown. Please post the complete error message incl. stack, cause the error message also show the file where the error occurs incl. line number. – CodyKL Feb 12 '20 at 04:44
  • @CodyKL I've added the rest – GingerFish Feb 12 '20 at 08:14
  • Which version of this package you use? And can you please show the related line code of this file where the error points to? – CodyKL Feb 12 '20 at 10:40
  • @CodyKL I've added more details in, with the function the error happens in, I've highlighted the line too – GingerFish Feb 12 '20 at 10:45
  • So, now you can go ahead and fix the issue byself, like @Nico Haase has suggested in his answer below. At the same time, you can inform the maintainer of this package to fix this bug. – CodyKL Feb 12 '20 at 10:53
  • @CodyKL I've tried your way and i'm still getting the same issue, I've updated my question with the info yourself and others have asked for. – GingerFish Feb 12 '20 at 11:55

0 Answers0