1.安裝swoole
pecl install swoole
查看swoole支持功能及安裝版本
php72 --ri swoole
swoole
Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.4
Built => Aug 22 2019 05:09:21
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2k-fips 26 Jan 2017
http2 => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => 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
2.錯(cuò)誤處理
2.1安裝過(guò)程中出現(xiàn)錯(cuò)誤:
'__builtin_saddl_overflow' was not declared in this scope
解決方案:
yum install centos-release-scl
yum install devtoolset-7
scl enable devtoolset-7 bash
2.2 加載順序錯(cuò)誤
php72 -m
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
原因:
擴(kuò)展加載順序問(wèn)題,swoole擴(kuò)展的加載位置寫在了php.ini中而mysqlnd的加載位置在php.d中,導(dǎo)致先加載了swoole后加載了mysqlnd擂涛,所以報(bào)了這個(gè)錯(cuò)誤
解決方法:
- 將mysqlnd的加載位置移動(dòng)至php.ini中。
- 在php.d中新建swoole.ini配置引入swoole擴(kuò)展。
二者相比較之下,更推薦后邊的做法授霸。
2.3 xdebug沖突
使用swoole開發(fā)Tcp服務(wù)器時(shí)與Xdebug產(chǎn)生沖突解決辦法
修改php.d下的xdebug.ini,將
zend_extension=xdebug.so
修改為:
;zend_extension=xdebug.so
3.使用swoole framework進(jìn)行功能開發(fā)
創(chuàng)建項(xiàng)目
composer create-project matyhtf/skeleton your_project_name
ps:安裝composer
curl -sS https://getcomposer.org/installer | php
編外:
swoole 給php語(yǔ)言提供另外一種截然不同的編程方式际插,豐富了PHP語(yǔ)言可以應(yīng)用的領(lǐng)域碘耳。但是與之對(duì)應(yīng)的框架官方文檔過(guò)于簡(jiǎn)單了,希望這次能夠根據(jù)這次的項(xiàng)目,總結(jié)一份有關(guān)框架使用的說(shuō)明文檔,能夠給希望使用這個(gè)框架的人一定的參考丧蘸。