Home  >  Article  >  PHP Framework  >  What to do if the swoole extension installation fails

What to do if the swoole extension installation fails

藏色散人
藏色散人Original
2020-02-04 15:06:343918browse

What to do if the swoole extension installation fails

What should I do if the swoole extension installation fails? Detailed explanation of swoole installation error

Recommended study: swoole tutorial

Today I installed swoole through pecl

pecl install swoole

The steps are very simple, but the installation was successful in the end Later, I found that the swoole extension was not displayed in phpinfo(). I executed:

php -m | grep swoole

and found the following error:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/ php/modules/swoole.so' - /usr/lib64/php/modules/swoole.so: undefined symbol: mysqlnd_find_charset_nr in Unknown on line 0

Looking carefully at the error report, I found that this error report is caused by swoole .so is reported, indicating that mysqlnd_find_charset_nr is not found when loading swoole.so. This is a keyword starting with mysqlnd, and mysqlnd is an extension of PHP. By reading swoole/swoole.mysql.c We found the following section of the source code:

const MYSQLND_CHARSET* cset = mysqlnd_find_charset_nr(client->connector.character_set);
 
if (cset == NULL)
{
 
    swoole_php_fatal_error(E_ERROR, "unknown mysql charset[%s].", client->connector.character_set);
 
    RETURN_FALSE;
 
}

From the above source code we can see that swoole needs to rely on the msyqlnd extension. We found that the msyqlnd extension exists in phpinfo(). Why is this reported? Wrong.

Finally, I found that the extensions loaded by PHP by default are in the directory /usr/lib64/php/modules/. The .so files here are loaded by default. The configuration of these extensions is not in /etc/ php.ini, but in the /etc/php.d/ directory. All .ini files in this directory are loaded after /etc/php.ini is loaded, and our extension=swoole. The configuration of so is written at the end of the /etc/php.ini file, so swoole.so is loaded first and then mysqlnd.so, which causes swoole to not find mysqlnd_find_charset_nr.

Solution:

1. Delete the mysqlnd.ini file in the /etc/php.d/ directory

2. Add extension=mysqlnd.so to the line above extension=swoole.so in /etc/php.ini

3. Restart php-fpm

This will solve the problem, same You may also encounter the following error:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/swoole.so' - /usr/lib64/php/ modules/swoole.so: undefined symbol: php_sockets_le_socket in Unknown on line 0

The solution is similar:

1. Change /etc/php Delete the sockets.ini file in the .d/ directory

2. Add extension=sockets.so in the line above extension=swoole.so in /etc/php.ini

3. Restart php-fpm

The above is the detailed content of What to do if the swoole extension installation fails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn