準備研究下php的網絡通訊,在swoole出現後愈來愈多phper開始使用它來作網絡編程相關的項目,項目的底層其實不少地方都涉及到網絡編程,因此就本身學習一下,就當知識擴展吧。php
pecl install swoole後執行php -m報以下錯誤,可見php並無識別到swoole擴展:編程
PHP Warning: PHP Startup: swoole: Unable to initialize moduleubuntu
Module compiled with module API=220121212swoole
PHP compiled with module API=20131226網絡
剛開始看到這個問題第一感受是以爲莫名奇妙,安裝php擴展實際上都是使用的phpize和php-config,而這些php的命令工具又屬於php5-dev(依賴包是開發php擴展的,提供一些用來開發、編譯php5擴展程序的必要php組件,通常是一些php源碼的頭文件和依賴庫,安裝後能夠經過dpkg-query -L php5-dev
)工具
網上查詢資料後發現多是php5-dev和php5的編譯API版本號不同,因而想從新安裝和php5一致的API版本號的php工具包,先卸載ubuntu14.04的工具包,在進行安裝學習
sudo apt-get remove php5-dev插件
sudo apt-get install php5-devcode
安裝成功後,從新在安裝swoole擴展,php -m依然出現上面的問題,因而運行開發
php -v
發現cli用的php5軟件包是,PHP 5.6.21-1+donate.sury.org~trusty+1 (cli)
而php5-dev的軟件包是,5.5.9+dfsg-1ubuntu4.20,發如今ubuntu 14.04上始終安裝的php5-dev都是此版本,終極解決辦法是再次卸載sudo apt-get remove php5-dev,手動安裝deb包
deb包下載網址
https://www.ubuntuupdates.org/package/core/wily/main/base/php5-dev
下載後使用sudo dpkg -i php5-dev_5.6.11+dfsg-1ubuntu3_amd64.deb安裝後再從新安裝擴展
先sudo pecl uninstall swoole在sudo pecl install swoole大功告成
附:
php和它的擴展插件不配對,不能初始化 #define PHP_5_0_X_API_NO 220040412 #define PHP_5_1_X_API_NO 220051025 #define PHP_5_2_X_API_NO 220060519 #define PHP_5_3_X_API_NO 220090626 #define PHP_5_4_X_API_NO 220100525 #define PHP_5_5_X_API_NO 220121212 #define PHP_5_6_X_API_NO 220131226