扩展工程

PHP-X是一个基于PHP ZendVM的C++封装层,可以基于PHP-X开发PHP扩展、C++嵌入PHP、PHP SAPI等程序。PHP-X可以大大降低PHP内核扩展开发的难度,提升效率。

环境依赖

  • PHP-7.0或更高版本
  • g++-4.8或更高版本或clang++,必须支持C++11标准
  • 仅支持 Linux/MacOS/Windows 3种平台
  • 仅支持 x86-64 架构
  • cmake-2.8或更高版本

编译安装

cmake .
make -j 4
sudo make install
sudo ldconfig

可以通过cmake -DPHP_CONFIG_DIR=/opt/php/bin指定php-config的路径
请检查libphpx.so是否存在于ldconfig -p

MacOS

编译时需要修改Makefile,为g++/clang++增加-undefined dynamic_lookup编译参数


  • 藩篱

    make install 之后,ldconfig 没有任何输出。 然后执行phpx提示没有该命令。 [root@localhost phpx-0.1.1]# cmake . -- The C compiler identification is GNU 4.8.5 -- The CXX compiler identification is GNU 4.8.5 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done PHP_INCLUDE_DIR: /usr/local/php7/include/php -- Configuring done -- Generating done -- Build files have been written to: /root/phpx/phpx-0.1.1 [root@localhost phpx-0.1.1]# make -j 4 Scanning dependencies of target phpx [ 10%] [ 20%] [ 30%] Building CXX object CMakeFiles/phpx.dir/src/array.o Building CXX object CMakeFiles/phpx.dir/src/base.o Building CXX object CMakeFiles/phpx.dir/src/class.o [ 40%] Building CXX object CMakeFiles/phpx.dir/src/exec.o [ 50%] Building CXX object CMakeFiles/phpx.dir/src/extension.o [ 60%] Building CXX object CMakeFiles/phpx.dir/src/function.o [ 70%] Building CXX object CMakeFiles/phpx.dir/src/hash.o [ 80%] Building CXX object CMakeFiles/phpx.dir/src/object.o [ 90%] Building CXX object CMakeFiles/phpx.dir/src/string.o [100%] Building CXX object CMakeFiles/phpx.dir/src/variant.o Linking CXX shared library lib/libphpx.so [100%] Built target phpx [root@localhost phpx-0.1.1]# sudo make install [100%] Built target phpx Install the project... -- Install configuration: "Debug" Are you run command using root user? -- Installing: /usr/local/lib/libphpx.so -- Up-to-date: /usr/local/include/phpx.h -- Up-to-date: /usr/local/include/phpx_embed.h [root@localhost phpx-0.1.1]# ll /usr/local/lib lib/ lib64/ libexec/ [root@localhost phpx-0.1.1]# ll /usr/local/lib lib/ lib64/ libexec/ [root@localhost phpx-0.1.1]# ll /usr/local/lib/libphpx.so build.sh CMakeFiles/ CMakeLists.txt examples/ include/ lib/ logo.png phpinfo.php script/ .travis.yml CMakeCache.txt cmake_install.cmake console/ .gitignore install_manifest.txt LICENSE Makefile README.md src/
    [root@localhost phpx-0.1.1]# ll /usr/local/lib/libphpx.so build.sh CMakeFiles/ CMakeLists.txt examples/ include/ lib/ logo.png phpinfo.php script/ .travis.yml CMakeCache.txt cmake_install.cmake console/ .gitignore install_manifest.txt LICENSE Makefile README.md src/
    [root@localhost phpx-0.1.1]# ldconfig [root@localhost phpx-0.1.1]#

  • 藩篱

    php版本7.2,cmake版本 2.8.12.2

  • 藩篱

    按照韩老大的这篇文章指引,正确切进来了。(^-^)V https://segmentfault.com/a/1190000011111074