由于项目是基于SwooleDistributed2.x
的,就将服务器的swoole4版本换成了swoole1.9版本。
添加redis扩展需要先下载hiredis类库,开始由于没有hiredis编译的时候就报了hiredis/hiredis.h: No such file or directory
这个错误。
安装hiredis
wget https://github.com/redis/hiredis/archive/v0.14.0.tar.gz
mv v0.14.0.tar.gz hiredis-0.14.0.tar.gz
tar xzvf hiredis-0.14.0.tar.gz
cd hiredis-0.14.0
make && make install
# 在底部添加这行环境变量 #
vim /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
source /etc/profile
# 安装完成如果php扩展目录没有libhiredis.so,复制过去即可
cp libhiredis.so /usr/local/php/lib/php/extensions/no-debug-zts-20170718
编译swoole
./configure --enable-openssl --enable-async-redis --with-php-config=/usr/local/php/bin/php-config
make clean
make
make && make install
然后发现php有个报错
[root@localhost hiredis-0.14.0]# php -v
PHP Warning: PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /usr/local/php/lib/php/extensions/no-debug-zts-20170718/swoole.so (libhiredis.so.0.14: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-zts-20170718/swoole.so.so (/usr/local/php/lib/php/extensions/no-debug-zts-20170718/swoole.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.2.6 (cli) (built: Mar 3 2019 20:05:09) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
解决办法
vi /etc/ld.so.conf
# 添加以下内容
include /usr/local/lib
# 执行
ldconfig
再次查看没有问题了
[root@localhost hiredis-0.14.0]# php -v
PHP 7.2.6 (cli) (built: Mar 3 2019 20:05:09) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
然后试着运行下SwooleDistributed项目,发现启动成功了。
[root@localhost bin]# php start_swoole_server.php start
------------------------ SWOOLE_DISTRIBUTED ---------------------------
System:Linux SwooleDistributed version:2.7.5.2
Swoole version: 1.9.23 PHP version: 7.2.6
worker_num: 4 task_num: 5
------------------------------SERVER-----------------------------------
S_TYPE S_NAME S_PORT S_PACK S_MIDD
WebSocket 0.0.0.0 9542 NonJsonPack [MonitorMiddleware][NormalHttpMiddleware]
CLUSTER 0.0.0.0 9999 [CLOSE]
-----------------------------------------------
[STA] Press Ctrl-C to quit. Start success.