編譯&安裝
cd swoole-src-2.0.6/ 下,
1.使用phpize來生成php編譯配置
2.使用./configure 來做編譯配置檢測(cè)
3.make進(jìn)行編譯,make install進(jìn)行安裝
命令執(zhí)行如下:
[root@php7 swoole-src-2.0.6]# phpize [root@php7 swoole-src-2.0.6]# ./configure [root@php7 swoole-src-2.0.6]# make && make install
4.make install后,如果正確,會(huì)出現(xiàn)以下內(nèi)容
[root@php7 swoole-src-2.0.6]# make install Installing shared extensions: /usr/lib64/php/modules/
修改配置文件
要能夠使用該模塊,還需要在 php.ini 文件中添加該模塊。
extension=swoole.so
重啟服務(wù)
新增php模塊后,需要重新啟動(dòng)nginx和php-fpm服務(wù),才會(huì)生效。
最后通過php -m或phpinfo()來查看是否成功加載了swoole。
注意:
1.swoole_server只能用于php-cli環(huán)境,否則會(huì)拋出致命錯(cuò)誤。
2.因此引入類/函數(shù)的php文件時(shí)必須要使用include_once或require_once,否會(huì)發(fā)生cannot redeclare function/class 的致命錯(cuò)誤。
3.不要用exit()/die(),會(huì)導(dǎo)致worker進(jìn)程退出。
4.PHP代碼中如果有異常拋出,必須在回調(diào)函數(shù)中進(jìn)行try/catch捕獲異常,否則會(huì)導(dǎo)致工作進(jìn)程退出。
推薦:php常見問題欄目