openwrt 安装swoole

本文记录了在OpenWRT系统中安装PHP扩展Swoole的详细步骤,包括下载软件包,修改Makefile,解决因OpenWRT使用uLibc库导致的编译错误,以及在缺少ucontext导致的协程问题。最终通过调整编译配置和源码,成功在OpenWRT上运行Swoole。
摘要由CSDN通过智能技术生成

本人所写的博客都为开发之中遇到问题记录的随笔,主要是给自己积累些问题。免日后无印象,如有不当之处敬请指正(欢迎进扣群 24849632 探讨问题);

打算在在openwrt下安装PHP扩展swoole,下面记录相关的过程:

swoole在PECL地址为:http://pecl.php.net/package/swoole

先下载最新的软件包swoole-4.4.16.tgz ,并移动openwrt/dl目录下

root# cd openwrt

root# mkdir -p package/utils/php7

root# cp feeds/packages/lang/php7-pecl-redis/ package/utils/php7/php7-pecl-swoole -rf

root# sha256sum dl/swoole-4.4.16.tgz

   04864e1b705c2b62198a5f3890dd3c23f95a4787c97f3c1b086f0367bdaf9a87  dl/swoole-4.4.16.tgz

root# vim package/utils/php7/php7-pecl-swoole/Makefile

#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PECL_NAME:=swoole
PECL_LONGNAME:=Bindings for the libswoole library

PKG_VERSION:=4.4.16
PKG_RELEASE:=16
PKG_HASH:=04864e1b705c2b62198a5f3890dd3c23f95a4787c97f3c1b086f0367bdaf9a87

PKG_NAME:=php7-pecl-swoole
PKG_SOURCE:=$(PECL_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=http://pecl.php.net/get/

PKG_MAINTAINER:=shen zhe <shenzhe163 at gmail dot com> (developer)\
Han Tianfeng <mikan dot tenny at gmail dot com> (lead)\
QiHao ChenCao <twose at qq dot com>

PKG_LICENSE:=Apache2.0
PKG_LICENSE_FILES:=LICENSE

PKG_BUILD_DEPENDS:=php7
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include $(TOPDIR)/feeds/packages/lang/php7/pecl.mk

CONFIGURE_ARGS+= "$(STAGING_DIR)/usr"

$(eval $(call PECLPackage,swoole,$(PECL_LONGNAME),+libstdc++,15))
$(eval $(call BuildPackage,$(PKG_NAME)))

:wq

root# ./scripts/feeds update -p local

root# ./scripts/feeds install -p local

root# make meunconfig

sel swoole
选中SWOOLE插件

 

root# make V=s

编译出现如下错误

make[4]: Leaving directory '/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16'
touch /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.built
rm -rf /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole.installed /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole
mkdir -p /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole
install -d -m0755 /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole/usr/lib/php
install -m0755 /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/modules/swoole.so /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole/usr/lib/php/
install -d -m0755 /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole/etc/php7
echo "extension=swoole.so" > /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole/etc/php7/15_swoole.ini
touch /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole.installed
mkdir -p /home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/root-ramips/stamp
SHELL= flock /home/bruce/MT7260/openwrt/tmp/.root-copy.flock -c 'cp -fpR /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.pkgdir/php7-pecl-swoole/. /home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/root-ramips/'
touch /home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/root-ramips/stamp/.php7-pecl-swoole_installed
mkdir -p /home/bruce/MT7260/openwrt/bin/targets/ramips/mt7620/packages /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/ipkg-mipsel_24kc/php7-pecl-swoole/CONTROL /home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/pkginfo
install -d -m0755 /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/ipkg-mipsel_24kc/php7-pecl-swoole/usr/lib/php
install -m0755 /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/modules/swoole.so /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/ipkg-mipsel_24kc/php7-pecl-swoole/usr/lib/php/
install -d -m0755 /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/ipkg-mipsel_24kc/php7-pecl-swoole/etc/php7
echo "extension=swoole.so" > /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/ipkg-mipsel_24kc/php7-pecl-swoole/etc/php7/15_swoole.ini
find /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/ipkg-mipsel_24kc/php7-pecl-swoole -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| xargs -r rm -rf
Package php7-pecl-swoole is missing dependencies for the following libraries:
libstdc++.so.6
Makefile:37: recipe for target '/home/bruce/MT7260/openwrt/bin/packages/mipsel_24kc/base/php7-pecl-swoole_4.4.16-16_mipsel_24kc.ipk' failed
make[3]: *** [/home/bruce/MT7260/openwrt/bin/packages/mipsel_24kc/base/php7-pecl-swoole_4.4.16-16_mipsel_24kc.ipk] Error 1
make[3]: Leaving directory '/home/bruce/MT7260/openwrt/package/utils/php7/php7-pecl-swoole'
time: package/utils/php7/php7-pecl-swoole/compile#200.25#22.59#214.86
package/Makefile:111: recipe for target 'package/utils/php7/php7-pecl-swoole/compile' failed
make[2]: *** [package/utils/php7/php7-pecl-swoole/compile] Error 2
make[2]: Leaving directory '/home/bruce/MT7260/openwrt'
package/Makefile:107: recipe for target '/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile' failed
make[1]: *** [/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile] Error 2
make[1]: Leaving directory '/home/bruce/MT7260/openwrt'
/home/bruce/MT7260/openwrt/include/toplevel.mk:225: recipe for target 'world' failed
make: *** [world] Error 2
root#  

解决办法:

这个问题,我尝试解决花了两天的时间,通过查看Makefile,发现是因为openwrt在BulidPackage时会将所有的“+”号正则为空字符,因此最后添加的依赖变成了libstdc, 导致在打包为IPK时不成功,修改相应的依赖信息为libstdcpp,成功完成编译

#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PECL_NAME:=swoole
PECL_LONGNAME:=Bindings for the libswoole library

PKG_VERSION:=4.4.16
PKG_RELEASE:=16
PKG_HASH:=04864e1b705c2b62198a5f3890dd3c23f95a4787c97f3c1b086f0367bdaf9a87

PKG_NAME:=php7-pecl-swoole
PKG_SOURCE:=$(PECL_NAME)-$(PKG_VERSION).tgz
PKG_SOURCE_URL:=http://pecl.php.net/get/

PKG_MAINTAINER:=shen zhe <shenzhe163 at gmail dot com> (developer)\
Han Tianfeng <mikan dot tenny at gmail dot com> (lead)\
QiHao ChenCao <twose at qq dot com>

PKG_LICENSE:=Apache2.0
PKG_LICENSE_FILES:=LICENSE

PKG_BUILD_DEPENDS:=php7
PKG_BUILD_DIR:=$(BUILD_DIR)/pecl-php7/$(PECL_NAME)-$(PKG_VERSION)
PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include $(TOPDIR)/feeds/packages/lang/php7/pecl.mk


# CONFIGURE_ARGS+= \
# 	--enable-openssl \
# 	--enable-http2 \
# 	--enable-sockets \
# 	--enable-debug \
# 	--enable-debug-log

$(eval $(call PECLPackage,swoole,$(PECL_LONGNAME),+libstdcpp,15))
$(eval $(call BuildPackage,$(PKG_NAME)))

欣喜之时,赶紧将生成的镜像写入了开发板并创建了相应的测试程序

<?php
	//高性能HTTP服务器
    $http = new Swoole\Http\Server("0.0.0.0", 9501);

    $http->on("start", function ($server) {
        echo "Swoole http server is started at http://127.0.0.1:9501\n";
    });

    $http->on("request", function ($request, $response) {
        $response->header("Content-Type", "text/plain");
        $response->end("Hello World\n");
    });

    $http->start();

赶紧运行, 

Swoole信息

什么鬼??

在swoole群内发布了相关的问题,得到了swoole开发者韩天峰的耐心指导,综合判断为OpenWRT使用的C库为uLibc, 不包含ucontext, 并解释了实现协程的三种实现方式

1: boost context asm ,

2: glibc ucontext,

3: c++11 thread

因为glibc内置的协程函数uclibc内并不存在,因此大韩分别给出了另二个实现方案的解决办法,分别是:

1,修改config.h, 在config.h中定义SW_USE_THREAD_CONTEXT 宏(此方法对应C++11 thread)

#define SW_USE_THREAD_CONTEXT 1

此方法经测试无效,故只能测试第一种方法,使用boost context asm方法; 

2,修改config.m4文件, c启用 boost asm (此方法对应boost context asm)

    elif test "$SW_CPU" = "mips32"; then
        if test "$SW_OS" = "LINUX"; then
           SW_CONTEXT_ASM_FILE="mips32_o32_elf_gas.S"
        else
            SW_USE_ASM_CONTEXT="no"
        fi
    else
        SW_USE_ASM_CONTEXT="no"
    fi

这种方式其实已经实现了,有可能是在OpenWRT平台下,CPU这识别错误导致无法加载协程实现文件造成的,相关的情况需要进一步确认Makefile的信息。 

检查后发现在swoole的config.m4文件中没有判断mipsel簇CPU的方法(己向swoole提交PR),修改如下(L554):

    AS_CASE([$host_cpu],
      [x86_64*], [SW_CPU="x86_64"],
      [x86*], [SW_CPU="x86"],
      [i?86*], [SW_CPU="x86"],
      [arm*], [SW_CPU="arm"],
      [aarch64*], [SW_CPU="arm64"],
      [arm64*], [SW_CPU="arm64"],
      [mips*], [SW_CPU="mips32"],
      [
        SW_USE_ASM_CONTEXT="no"
      ]
    )

在这个Case内增加了mips簇的检测分支,并将工程移出feeds目录,重新在menuconfig中选中并编译

 mipsel-openwrt-linux-musl-gcc -I. -I/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16 -DPHP_ATOM_INC -I/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/include -I/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/main -I/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16 -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/include/php7 -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/include/php7/main -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/include/php7/TSRM -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/include/php7/Zend -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/include/php7/ext -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/include/php7/ext/date/lib -I/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16 -I/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/include -I/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/hiredis -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/include -I/home/bruce/MT7260/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.3.0_musl/usr/include -I/home/bruce/MT7260/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.3.0_musl/include/fortify -I/home/bruce/MT7260/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.3.0_musl/include -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/lib/libiconv-stub/include -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/lib/libintl-stub/include -DHAVE_CONFIG_H -Wall -pthread -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -ffile-prefix-map=/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16=swoole-4.4.16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/lib/libiconv-stub/include -I/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/usr/lib/libintl-stub/include -c /home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S  -fPIC -DPIC -o thirdparty/boost/asm/.libs/make_mips32_o32_elf_gas.o
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S: Assembler messages:
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:42: Error: .cpload not supported in MIPS16 mode
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:50: Error: operand value out of range for instruction
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:51: Error: invalid operands `and $v0,$v1,$v0'
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:61: Error: invalid operands `sw $gp,48($v0)'
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:64: Error: invalid operands `la $t9,finish'
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:67: Error: invalid operands `sw $t9,84($v0)'
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:82: Error: invalid operands `lw $t9,%call16(_exit)($gp)'
/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/thirdparty/boost/asm/make_mips32_o32_elf_gas.S:84: Error: invalid operands `jalr $t9'
Makefile:458: recipe for target 'thirdparty/boost/asm/make_mips32_o32_elf_gas.lo' failed
make[4]: *** [thirdparty/boost/asm/make_mips32_o32_elf_gas.lo] Error 1
make[4]: Leaving directory '/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16'
Makefile:44: recipe for target '/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.built' failed
make[3]: *** [/home/bruce/MT7260/openwrt/build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/.built] Error 2
make[3]: Leaving directory '/home/bruce/MT7260/openwrt/package/lang/swoole-4.4.16'
time: package/lang/swoole-4.4.16/compile#198.40#22.16#213.46
package/Makefile:111: recipe for target 'package/lang/swoole-4.4.16/compile' failed
make[2]: *** [package/lang/swoole-4.4.16/compile] Error 2
make[2]: Leaving directory '/home/bruce/MT7260/openwrt'
package/Makefile:107: recipe for target '/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile' failed
make[1]: *** [/home/bruce/MT7260/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.package_compile] Error 2
make[1]: Leaving directory '/home/bruce/MT7260/openwrt'
/home/bruce/MT7260/openwrt/include/toplevel.mk:225: recipe for target 'world' failed
make: *** [world] Error 2

这又是什么情况??引入的ASM文件无法编译吗?直接CD到swoole的目录,使用宿主机编译,成功且汇编文件夹内也生成了中间文件lo, 仔细看了下错误,原来是用了GCC编译器,那只能改AS汇编器看看能怎么样,但PHPIZE生成的autoconf怎么修改编译器呢?经过查看生成的相关文件,信息将线索引入到了php目录文件夹,那么先修改下php.m4文件,再试一下

root#  cd build_dir/target-mipsel_24kc_musl/php-7.4.3/build/

root#  vim php.m4

dnl
dnl PHP_SUBST(varname)
dnl
dnl Adds variable with it's value into Makefile, e.g.:
dnl AS = as
dnl
AC_DEFUN([PHP_SUBST],[
  PHP_VAR_SUBST="$PHP_VAR_SUBST $1"
])

先在第90行的位置,定义AS汇编器

dnl
dnl _PHP_ASSIGN_BUILD_VARS(type)
dnl
dnl Internal, don't use.
dnl
AC_DEFUN([_PHP_ASSIGN_BUILD_VARS],[
ifelse($1,shared,[
  b_s_pre=$shared_s_pre
  b_c_pre=$shared_c_pre
  b_cxx_pre=$shared_cxx_pre
  b_c_meta=$shared_c_meta
  b_cxx_meta=$shared_cxx_meta
  b_c_post=$shared_c_post
  b_cxx_post=$shared_cxx_post
],[
  b_s_pre=$php_s_pre
  b_c_pre=$php_c_pre
  b_cxx_pre=$php_cxx_pre
  b_c_meta=$php_c_meta
  b_cxx_meta=$php_cxx_meta
  b_c_post=$php_c_post
  b_cxx_post=$php_cxx_post
])dnl
  b_lo=[$]$1_lo
])

在第206行的位置增加  b_s_pre=$shared_s_preb_s_pre=$php_s_pre 两个变量定义

dnl
dnl PHP_BUILD_SHARED
dnl
AC_DEFUN([PHP_BUILD_SHARED],[
  PHP_BUILD_PROGRAM
  OVERALL_TARGET=libphp[]$PHP_MAJOR_VERSION[.la]
  php_sapi_module=shared

  php_s_pre=$shared_s_pre
  php_c_pre=$shared_c_pre
  php_c_meta=$shared_c_meta
  php_c_post=$shared_c_post
  php_cxx_pre=$shared_cxx_pre
  php_cxx_meta=$shared_cxx_meta
  php_cxx_post=$shared_cxx_post
  php_lo=$shared_lo
])

第780行位置增加  php_s_pre=$shared_s_pre  变量定义

dnl
AC_DEFUN([PHP_BUILD_PROGRAM],[
  php_s_pre='$(LIBTOOL) --mode=compile $(AS)'
  php_c_pre='$(LIBTOOL) --mode=compile $(CC)'
  php_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS)'
  php_c_post=
  php_cxx_pre='$(LIBTOOL) --mode=compile $(CXX)'
  php_cxx_meta='$(COMMON_FLAGS) $(CXXFLAGS_CLEAN) $(EXTRA_CXXFLAGS)'
  php_cxx_post=
  php_lo=lo

  case $with_pic in
    yes) pic_setting='-prefer-pic';;
    no)  pic_setting='-prefer-non-pic';;
  esac

  shared_s_pre='$(LIBTOOL) --mode=compile $(AS)'
  shared_c_pre='$(LIBTOOL) --mode=compile $(CC)'
  shared_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) '$pic_setting
  shared_c_post=
  shared_cxx_pre='$(LIBTOOL) --mode=compile $(CXX)'
  shared_cxx_meta='$(COMMON_FLAGS) $(CXXFLAGS_CLEAN) $(EXTRA_CXXFLAGS) '$pic_setting
  shared_cxx_post=
  shared_lo=lo
])

第818行位置增加   shared_s_pre='$(LIBTOOL) --mode=compile $(AS)' 定义

dnl Choose the right compiler/flags/etc. for the source-file.
      case $ac_src in
        *.c[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        # *.s[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        # *.S[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        *.s[)] ac_comp="$b_s_pre -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        *.S[)] ac_comp="$b_s_pre -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        *.cpp|*.cc|*.cxx[)] ac_comp="$b_cxx_pre $3 $ac_inc $b_cxx_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_cxx_post" ;;
      esac

修改第264行处

        *.s[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        *.S[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;

        # *.s[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        # *.S[)] ac_comp="$b_c_pre $3 $ac_inc $b_c_meta -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        *.s[)] ac_comp="$b_s_pre -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;
        *.S[)] ac_comp="$b_s_pre -c $ac_srcdir$ac_src -o $ac_bdir$ac_obj.$b_lo $6$b_c_post" ;;

:wq 保存退出,并回到openwrt目录,同时删除bulid_dir目录下的swoole文件夹

(此文件己生成patch, 可在文后下载放入 package/feeds/packages/php7/patches/ 目录即可

 

root#  rm build_dir/target-mipsel_24kc_musl/pecl-php7/swoole-4.4.16/ -rf

重新编译,得到新的固件,下载到开发板

root@OpenWrt:/www# php-cli  httpd.php
[  109.167824] php-cli invoked oom-killer: gfp_mask=0x14200ca(GFP_HIGHUSER_MOVABLE), nodemask=(null),  order=0, oom_score_adj=0
[  109.179377] CPU: 0 PID: 2170 Comm: php-cli Not tainted 4.14.171 #0
[  109.185692] Stack : 804f0000 80499bdc 00000000 00000000 80471d9c 80d5fc04 839982fc 804c3a27
[  109.194246]         8046dd28 0000087a 80f73660 00000800 00000040 00000001 80d5fbb8 7e62a21c
[  109.202797]         00000000 00000000 80f70000 80f77e68 00000000 00000173 00000007 00000000
[  0000 0002bcb1 ffffffff 80000000 83998000 80d5fd98 80476700
[  109.219890]         000000a9 00000800 00000040 014200ca 00000001 802310fc 00000000 80f70000
[  109.228439]         ...
[  109.230950] Call Trace:
[  109.233474] [<8000ad84>] show_stack+0x58/0x100
[  109.238030] [<800acb28>] dump_header+0x98/0x200
[  109.242671] [<800abc7c>] oom_kill_process+0xd0/0x494
[  109.247739] [<800ac9c4>] out_of_memory+0x2c0/0x310
[  109.252648] [<800b0ebc>] __alloc_pages_nodemask+0x834/0xc9c
[  109.258336] [<800d8990>] handle_mm_fault+0x2fc/0xdb4
[  109.263426] [<80012950>] __do_page_fault+0x1e0/0x4fc
[  109.268501] [<80018c10>] tlb_do_page_fault_1+0x10c/0x11c
[  109.273931] Mem-Info:
[  109.276271] active_anon:746 inactive_anon:519 isolated_anon:0
[  109.276271]  active_file:0 inactive_file:0 isolated_file:0
[  109.276271]  unevictable:8852 dirty:0 writeback:0 unstable:0
[  109.276271]  slab_reclaimable:286 slab_unreclaimable:898
[  109.276271]  mapped:2532 shmem:528 pagetables:62 bounce:0
[  109.276271]  free:2048 free_pcp:1 free_cma:0
[  109.308753] Node 0 active_anon:2984kB inactive_anon:2076kB active_file:0kB in
active_file:0kB unevictable:35408kB isolated(anon):0kB isolated(file):0kB mapped
:10128kB dirty:0kB writeback:0kB shmem:2112kB writeback_tmp:0kB unstable:0kB all
_unreclaimable? yes
[  109.331924] Normal free:8192kB min:8192kB low:10240kB high:12288kB active_ano
n:2984kB inactive_anon:2076kB active_file:0kB inactive_file:0kB unevictable:3540
8kB writepending:0kB present:65536kB managed:59540kB mlocked:0kB kernel_stack:27
2kB pagetables:248kB bounce:0kB free_pcp:4kB local_pcp:4kB free_cma:0kB
[  109.359669] lowmem_reserve[]: 0 0
[  109.363060] Normal: 18*4kB (UE) 19*8kB (UME) 6*16kB (UME) 4*32kB (UM) 3*64kB
(UE) 3*128kB (UME) 2*256kB (UM) 1*512kB (E) 2*1024kB (ME) 2*2048kB (M) 0*4096kB
= 8192kB
[  109.378214] 9380 total pagecache pages
[  109.382047] 0 pages in swap cache
[  109.385427] Swap cache stats: add 0, delete 0, find 0/0
[  109.390761] Free swap  = 0kB
[  109.393696] Total swap = 0kB
[  109.396631] 16384 pages RAM
[  109.399475] 0 pages HighMem/MovableOnly
[  109.403394] 1499 pages reserved
[  109.406595] [ pid ]   uid  tgid total_vm      rss nr_ptes nr_pmds swapents oom_score_adj  name
[  109.415315] [  474]     0   474      306      201       5       0        0          0       ubusd
[  109.424117] [  475]     0   475      304      241       5       0        0          0       ash
[  109.432742] [ 1021]     0  1021      467      264       4       0        0          0       rpcd
[  109.441454] [ 1066]     0  1066      276      214       4       0        0          0       dropbear
[  109.450510] [ 1117]     0  1117      427      265       4       0        0          0       netifd
[  109.459400] [ 1382]     0  1382      302      223       4       0        0          0       udhcpc
[  109.468290] [ 1915]     0  1915      294      226       4       0        0          0       dropbear
[  109.477355] [ 1916]     0  1916      304      240       5       0        0          0       ash
[  109.485979] [ 1945]     0  1945      378      248       4       0        0          0       dbus-daemon
[  109.495311] [ 1969] 65534  1969      507      335       4       0        0          0       avahi-daemon
[  109.504732] [ 2001]     0  2001      366      218       4       0        0          0       blockd
[  109.513623] [ 2139]     0  2139      302      223       4       0        0          0       ntpd
[  109.522337] [ 2170]     0  2170     3711     2587       7       0        0          0       php-cli
[  109.531310] Out of memory: Kill process 2170 (php-cli) score 169 or sacrifice child
[  109.539137] Killed process 2170 (php-cli) total-vm:14844kB, anon-rss:1892kB,file-rss:6400kB, shmem-rss:2056kB
[  109.555165] oom_reaper: reaped process 2170 (php-cli), now anon-rss:0kB, file-rss:0kB, shmem-rss:2052kB
Killed
root@OpenWrt:/www#

swoole组件已经成功运行,但申请的内存过多,造成进程被Kernel Kill掉了,需要再修改测试文件的配置测试

Co\run(function () {
    $server = new Co\Http\Server("0.0.0.0", 9501, false);
    $server->handle('/', function ($request, $response) {
        $response->end("<h1>Index</h1>");
    });
    $server->handle('/test', function ($request, $response) {
        $response->end("<h1>Test</h1>");
    });
    $server->handle('/stop', function ($request, $response) use ($server) {
        $response->end("<h1>Stop</h1>");
        $server->shutdown();
    });
    $server->start();
});

示例来自 https://wiki.swoole.com/#/coroutine/http_server

重新在在开发板内运行,并使用浏览器打开

很好,一切正常!

全文完 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晶通物控

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值