brick / math

Arbitrary-precision arithmetic library for PHP
MIT License
1.78k stars 75 forks source link

Fatal error: Maximum execution time of 30 seconds exceeded #56

Closed raduungurean closed 3 years ago

raduungurean commented 3 years ago

PHP Version 7.4.15

$fromBase = BrickBigInteger::fromBase("bd58e8d59e95cf0617f358b4106467af2ed6489d61af4e147e3582d8206888325ac52717344c4ad80b1e05507809ed19016a4d389a1d62e26724d52190a140768630e3c5b88f205b72f84727b265cf867321e50f29a48257da043a86a6db99d3fff1b2b390ea9f683a55f60061d963e59aae38eecc56b3b23816d923da2154b5b8581ab65e9151f003c43231bb7b0f95d4866adf04da2e4986cf843c9999f351ff915cf73355e0ad397544242c383bb7850320af30e696da693e535f2e99b4eed034f85f0b02f28fda140235b759d41a2fbddfb70271715f90f927414dd9a8565047597fd2b932ec8ee070e888342ef47c195575782a5aa4be1040dd89fad605e522e66f9ad4f97c2e473e91801111c237972525f14247924f87fdcc9305716ce9c6cd5f1166eae642081e5de0fbfe02d87154178cc5eae4ebb31879eab82da400d266391ccb1bc6e6986c4c497b7cb025c5910e95fd053238b68f305955fa0df4ba2e34fdef4749f511c622b19c476f398d1518bdcf734afa88779c0550b0b65e42043c400040086279689764af9767753ebc9dae54cc7036f43222fe9189749a06a3825d1eff02a0a5a219f4740800d1dc94843470912f1f98a211b2a303fe33b867c34e4eb2d880b3cbe14a90541401d9c0bab7c1d09f47b9d0ff77484577a7c13f888350d39d29c03cccd62fe7ad6d3afda08564522b7c8ff0ae9963cfe3", 16);


Call Stack

1 | 0.0052 | 393368 | {main}( ) | .../index.php:0 2 | 0.0132 | 397736 | require( '/var/www/html/config/bootstrap.php ) | .../index.php:3 3 | 0.5040 | 2868464 | Brick\Math\BigInteger::fromBase( $number = '....', $base = 16 ) | .../bootstrap.php:21 4 | 0.5143 | 3005048 | Brick\Math\Internal\Calculator\NativeCalculator->fromBase( $number = '....', $b = '9' ) | .../Calculator.php:443 7 | 31.4177 | 3006616 | Brick\Math\Internal\Calculator\NativeCalculator->doMul( $a = '....', $b = '9' ) | .../NativeCalculator.php:130 8 | 31.4649 | 3007936 | Brick\Math\Internal\Calculator\NativeCalculator->add( $a = '.....', $b = '20885513040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ) | .../NativeCalculator.php:511 9 | 31.4649 | 3007936 | Brick\Math\Internal\Calculator\NativeCalculator->doAdd( $a = '....', $b = '20885513040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' )


This only happens when using a real hosting provider or a docker image. Works fine when using the php's built in server.

BenMorel commented 3 years ago

Hi, you're missing of the GMP or BCMath extensions on your server. The call stack shows that you're using the NativeCalculator, which is the fallback when both extensions are missing. It's quite slow, and although the above code takes ~1.5s to run of my machine, it can probably time out on a less performant server with large calculations like this one (the base conversion algorithm is quite expensive currently).

Install one of these extensions and you should be good!

raduungurean commented 3 years ago

Ok. Thanks for the clarification