Yii2 and gmp: Unable to load dynamic library gmp.so

Hi,

I’ve developed an application that requires the gmp library.

The library is enabled both in my local environment and in my remote hosting provider.
PHP versions: 7.2.24 (local) and 7.3.22 (remote)

Both on local and remote installations I can run code (say in independent php files) requiring the gmp library.
Also, in my local environment the developed application works fine.
But within Yii2 I get the following error that I don’t know how to solve:

yii\base\ErrorException: PHP Startup: Unable to load dynamic library 'gmp.so' (tried: /opt/alt/php73/usr/lib64/php/modules/gmp.so (/opt/alt/php73/usr/lib64/php/modules/gmp.so: cannot open shared object file: No such file or directory), /opt/alt/php73/usr/lib64/php/modules/gmp.so.so (/opt/alt/php73/usr/lib64/php/modules/gmp.so.so: cannot open shared object file: No such file or directory)) in Unknown:0
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}

Is it a server configuration problem?
If so, why I can run code with gmp anyway?

I’m quite not sure how to handle this. Any suggestion is appreciated.

Thanks

It looks to me that you have this library configured for the CLI PHP but not for CGI one.

I see, but if I create a file test.php, say outside of Yii, with code requiring the gmp library it works (in a web browser) without problems.

Hmm, really weird… When you pop script with phpinfo() in your browser does it show gnu multiple precision?

Yes, it does.

I include here two parts of my phpinfo().

Configure Command:

GMP:

I just add that on the remote installation at the bottom of every pages I see this:
**Fatal error** : Uncaught yii\web\HeadersAlreadySentException: Headers already sent in /home/tvlhwxbb/_comfort-kit/vendor/yiisoft/yii2/web/Response.php on line 430. in /home/tvlhwxbb/_comfort-kit/vendor/yiisoft/yii2/web/Response.php:366 Stack trace: #0 /home/tvlhwxbb/_comfort-kit/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders() #1 /home/tvlhwxbb/_comfort-kit/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send() #2 /home/tvlhwxbb/_comfort-kit/vendor/yiisoft/yii2/base/ErrorHandler.php(276): yii\web\ErrorHandler->renderException(Object(yii\base\ErrorException)) #3 [internal function]: yii\base\ErrorHandler->handleFatalError() #4 {main} thrown in **/home/tvlhwxbb/_comfort-kit/vendor/yiisoft/yii2/web/Response.php** on line **366**

I cannot use xdebug on my hosting so I cannot see where this is triggered. So I don’t see exaclty how the errors are triggered and neither if they are related.

So, after some hours trying to figure this out, I’ve rewritten the code to use bcmath instead of gmp but the errors keep showing up.
I’ve contacted the hosting support because it seems more clear that something is wrong with some server settings.

I’ve followed the suggestion found here about changing output_buffering. The way the errors show changes but it does not solve the issues.

I’ve copied the same application to another domain (same hosting) and it works fine.
Waiting for the hosting support to help out.

Some more behaviors not clear to me:

  • If I manually delete web/assets and runtime contents, the first time I open a page no error is displayed.

  • After any further action request the error Uncaught yii\web\HeadersAlreadySentException shows up

  • The error Unable to load dynamic library gmp.so shows up in fact each time I try to save any model. Worth noticing, the model gets saved.

  • I tried also to enable the debug bar and to look into each log “manually” with /debug/default/view?tag=debug_id. Still not sure if there is anything there that can help to figure this out.

  • It is quite a mistery to me why the gmp error shows up only when I try to save a model and why it shows up at all, given that I’m not using anymore any code with gmp now.

I’ve finally needed to have the gmp library disabled on the server.
Now all the errors are gone.

I will probably never know if this was due to yii or to some wrong server settings.