arnaud-lb / php-memory-profiler

Memory profiler for PHP. Helps finding memory leaks in PHP scripts.
MIT License
858 stars 51 forks source link

Extension doesn't seem to be loaded #61

Closed AlterWeb closed 2 years ago

AlterWeb commented 2 years ago

Hi,

I'm trying to install the extension but it looks like it is not loaded. Within the output of php_info() I see that the .ini config is loaded:

/etc/php/7.3/fpm/conf.d/20-memprof.ini:

This file contains the line:

extension=memprof.so

But if I look at the loaded extensions with the PHP function get_loaded_extensions() I don't see memprof showing up. Also no mention of anything related to this extension in the php_info() output except for the .ini file.

The memprof.so file is located in the extension_dir (/usr/lib/php/20180731) found in the output of php_info().

I restarted the PHP fpm service several times but without any luck. Are there any other steps I need to take?

arnaud-lb commented 2 years ago

Hi @AlterWeb

It's possible that the extension failed to load for some reason. Do you see anything in the logs ?

AlterWeb commented 2 years ago

@arnaud-lb Unfortunately there is nothing in the logs indicating what the problem could be. The only lines are (repeated for every time I restart PHP FPM):

[16-Nov-2021 15:02:06] NOTICE: fpm is running, pid ***** [16-Nov-2021 15:02:06] NOTICE: ready to handle connections [16-Nov-2021 15:02:06] NOTICE: systemd monitor interval set to 10000ms

arnaud-lb commented 2 years ago

Nothing in syslog either ?

AlterWeb commented 2 years ago

@arnaud-lb Thank you so much! That gives me at least some more information:

Nov 16 15:02:06 php-fpm7.3[12570]: [16-Nov-2021 15:02:06] NOTICE: PHP message: PHP Warning: PHP Startup: memprof: Unable to initialize module Nov 16 15:02:06 php-fpm7.3[12570]: Module compiled with module API=20170718 Nov 16 15:02:06 php-fpm7.3[12570]: PHP compiled with module API=20180731 Nov 16 15:02:06 php-fpm7.3[12570]: These options need to match Nov 16 15:02:06 php-fpm7.3[12570]: in Unknown on line 0 Nov 16 15:02:06 systemd[1]: Started The PHP 7.3 FastCGI Process Manager.

Do you know how I can get the right compiled version?

arnaud-lb commented 2 years ago

It looks like that the module was compiled with PHP 7.2. You need to reinstall/recompile it with PHP 7.3

AlterWeb commented 2 years ago

@arnaud-lb Thank you so much for your time.

I'm trying to do so but it keeps compiling for PHP 7.2 (the default PHP version of this server). I tried using PHP 7.3 by using the follow commands:

sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set phpize /usr/bin/phpize5.6

That seems to set the right PHP versions for my CLI:

php -v
PHP 7.3.27-9+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Feb 23 2021 15:10:08) ( NTS )
phpize -v
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731

But after running the installation lines:

phpize
./configure
make
make install

It says it is installed in the PHP 7.2 extensions directory:

Installing shared extensions: /usr/lib/php/20170718/

I tried copying this .so file but then I get back to the error in the syslog saying it's compiled with the wrong API.

arnaud-lb commented 2 years ago

You can explicitly specify the PHP version you want to build on by using the --with-php-config flag (e.g. ./configure --with-php-config=/usr/bin/php-config7.3)