環境說明及版本說明:
Homestead v10.7.0
swoole v4.4.17
1.安裝swoole
vagrant@homestead:~$ sudo pecl install swoole
- 遇到以下錯誤
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update Could not download from "https://pecl.php.net/get/mongodb-1.5.5.tgz", cannot download "pecl/mongodb" (Connection to `ssl://pecl.php.net:443' failed: ) Error: cannot download "pecl/mongodb" Download failed install failed
- 解決方法:
vagrant@homestead:~$ sudo pecl channel-update pecl.php.net
- 重新安裝
安裝的時候會有yes/no之類的選項,直接vagrant@homestead:~$ sudo pecl install swoole
enter
就可以了
出現如下文字說明已經安裝成功:Build process completed successfully Installing '/usr/lib/php/20180731/swoole.so' Installing '/usr/include/php/20180731/ext/swoole/config.h' install ok: channel://pecl.php.net/swoole-4.4.17 configuration option "php_ini" is not set to php.ini location You should add "extension=swoole.so" to php.ini
2.開啟擴充套件
- 檢視當前PHP版本
vagrant@homestead:~$ php -v PHP 7.3.7-2+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Jul 25 2019 11:44:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.7-2+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
- 建立配置檔案
vagrant@homestead:~$ sudo touch /etc/php/7.3/mods-available/swoole.ini
- 寫入以下內容
extension=swoole.so
- 新增軟連線
vagrant@homestead:/etc/php/7.3/cli/conf.d$ sudo ln -s /etc/php/7.3/mods-available/swoole.ini ./20-swoole.ini
- 重啟
php-fpm
sudo service php7.3-fpm restart
- 檢視擴充套件
如果出現以下內容說明已經安裝成功vagrant@homestead:/etc/php/7.3/cli/conf.d$ php --ri swoole
swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.17 Built => Apr 17 2020 20:14:41 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled pcre => enabled zlib => 1.2.11 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608
本作品採用《CC 協議》,轉載必須註明作者和本文連結