最近把 PHP7.4 升级为了 PHP8.1,安装 guzzlehttp/guzzle 的时候,Composer(version2.7.5)命令突然无法工作,不论换哪个版本都返回 Segmentation fault 分段错误。
根据经验判断,一般情况下只有可执行程序有问题,才会出现此类问题,所以去换了好几个旧版本的 Composer 发现也不行,最大的可能就是操作系统(CentOS7.9)太旧或者PHP扩展不兼容了。
由于站点需要 Swoole 版本装的是4.x最新版4.8.5,而pecl提供的最新版本已经是5.x了,尝试注释掉了 Swoole 扩展的引用就正常了。
编辑 /www/server/php/81/etc/php.ini 和 /www/server/php/81/etc/php-cli.ini
#extension = swoole.so
重启 PHP-FPM 进程
/etc/init.d/php-fpm-81 restart
再次使用 Composer 指令安装对应的包,就OK了。
[root@localhost zhujizixun.com]# sudo -u www ./composer.phar require guzzlehttp/guzzle
./composer.json has been updated
Running composer update guzzlehttp/guzzle
Loading composer repositories with package information
Updating dependencies
Lock file operations: 5 installs, 0 updates, 0 removals
- Locking guzzlehttp/guzzle (7.8.1)
- Locking guzzlehttp/promises (2.0.2)
- Locking guzzlehttp/psr7 (2.6.2)
- Locking ralouphie/getallheaders (3.0.3)
- Locking symfony/deprecation-contracts (v3.3.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
- Downloading symfony/deprecation-contracts (v3.3.0)
- Downloading ralouphie/getallheaders (3.0.3)
- Downloading guzzlehttp/psr7 (2.6.2)
- Downloading guzzlehttp/promises (2.0.2)
- Downloading guzzlehttp/guzzle (7.8.1)
- Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
- Installing ralouphie/getallheaders (3.0.3): Extracting archive
- Installing guzzlehttp/psr7 (2.6.2): Extracting archive
- Installing guzzlehttp/promises (2.0.2): Extracting archive
- Installing guzzlehttp/guzzle (7.8.1): Extracting archive
1 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
> @php think service:discover
Succeed!
> @php think vendor:publish
Succeed!
12 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Using version ^7.8 for guzzlehttp/guzzle
总结:Composer与PHP8+版本的扩展之间存在兼容问题。