由于项目是基于SwooleDistributed2.x的,就将服务器的swoole4版本换成了swoole1.9版本。

添加redis扩展需要先下载hiredis类库,开始由于没有hiredis编译的时候就报了hiredis/hiredis.h: No such file or directory这个错误。

安装hiredis

  1. wget https://github.com/redis/hiredis/archive/v0.14.0.tar.gz
  2. mv v0.14.0.tar.gz hiredis-0.14.0.tar.gz
  3. tar xzvf hiredis-0.14.0.tar.gz
  4. cd hiredis-0.14.0
  5. make && make install
  6. # 在底部添加这行环境变量 #
  7. vim /etc/profile
  8. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
  9. source /etc/profile
  10. # 安装完成如果php扩展目录没有libhiredis.so,复制过去即可
  11. cp libhiredis.so /usr/local/php/lib/php/extensions/no-debug-zts-20170718

编译swoole

  1. ./configure --enable-openssl --enable-async-redis --with-php-config=/usr/local/php/bin/php-config
  2. make clean
  3. make
  4. make && make install

然后发现php有个报错

  1. [root@localhost hiredis-0.14.0]# php -v
  2. 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
  3. PHP 7.2.6 (cli) (built: Mar 3 2019 20:05:09) ( ZTS )
  4. Copyright (c) 1997-2018 The PHP Group
  5. Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

解决办法

  1. vi /etc/ld.so.conf
  2. # 添加以下内容
  3. include /usr/local/lib
  4. # 执行
  5. ldconfig

再次查看没有问题了

  1. [root@localhost hiredis-0.14.0]# php -v
  2. PHP 7.2.6 (cli) (built: Mar 3 2019 20:05:09) ( ZTS )
  3. Copyright (c) 1997-2018 The PHP Group
  4. Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

然后试着运行下SwooleDistributed项目,发现启动成功了。

  1. [root@localhost bin]# php start_swoole_server.php start
  2. ------------------------ SWOOLE_DISTRIBUTED ---------------------------
  3. System:Linux SwooleDistributed version:2.7.5.2
  4. Swoole version: 1.9.23 PHP version: 7.2.6
  5. worker_num: 4 task_num: 5
  6. ------------------------------SERVER-----------------------------------
  7. S_TYPE S_NAME S_PORT S_PACK S_MIDD
  8. WebSocket 0.0.0.0 9542 NonJsonPack [MonitorMiddleware][NormalHttpMiddleware]
  9. CLUSTER 0.0.0.0 9999 [CLOSE]
  10. -----------------------------------------------
  11. [STA] Press Ctrl-C to quit. Start success.