Zephir - 是一种高级编程语言,可简化 PHP 扩展的创建和可维护性。Zephir 扩展导出为 C 代码,可以通过 gcc/clang/vc++ 等主要 C 编译器进行编译和优化。功能暴露给 PHP 语言。
GitHub https://github.com/zephir-lang/zephir
Zephir Parser https://github.com/zephir-lang/php-zephir-parser
Zephir Zephir Documentation
Zephir-Docs Building PHP extensions is easy with Zephir
安装 https://docs.zephir-lang.com/0.12/zh-cn/installation
sudo yum install gcc make re2c autoconf automake # 安装解析器 git clone https://github.com/zephir-lang/php-zephir-parser.git /usr/local/php81/bin/phpize ./configure --with-php-config=/usr/local/php81/bin/php-config make sudo make install sudo vim /usr/local/php81/etc/php.ini extension=zephir_parser ## 下载 php-8.1.1 源码 并 更新开发库 cd /usr/include/php # 备份原文件 sudo mkdir .bak sudo mv * ./.bak/ #引入新文件 sudo ln -s /data/install/php-8.1.1/ext /usr/include/php/ sudo ln -s /data/install/php-8.1.1/include /usr/include/php/ sudo ln -s /data/install/php-8.1.1/main /usr/include/php/ sudo ln -s /data/install/php-8.1.1/sapi /usr/include/php/ sudo ln -s /data/install/php-8.1.1/TSRM /usr/include/php/ sudo ln -s /data/install/php-8.1.1/Zend /usr/include/php/ # 安装 zephir git clone https://github.com/zephir-lang/zephir.git composer install chmod +x zephir sudo ln -s /data/www/jsx/zephir/zephir /usr/local/bin/ ✔> zephir _____ __ _ /__ / ___ ____ / /_ (_)____ / / / _ \/ __ \/ __ \/ / ___/ / /__/ __/ /_/ / / / / / / /____/\___/ .___/_/ /_/_/_/ /_/ Zephir 0.15.2 by Andres Gutierrez and Serghei Iakovlev (source) Usage: command [options] [arguments] Options: --dumpversion Print the version of the compiler and don't do anything else (also works with a single hyphen) -h, --help Print this help message --no-ansi Disable ANSI output -v, --verbose Displays more detail in error messages from exceptions generated by commands (can also disable with -V) --vernum Print the version of the compiler as integer --version Print compiler version information and quit Available commands: api Generates a HTML API based on the classes exposed in the extension build Generates/Compiles/Installs a Zephir extension clean Cleans any object files created by the extension compile Compile a Zephir extension fullclean Cleans any object files created by the extension (including files generated by phpize) generate Generates C code from the Zephir code without compiling it help Display help for a command init Initializes a Zephir extension install Installs the extension in the extension directory (may require root password) stubs Generates stubs that can be used in a PHP IDE
开发扩展 https://docs.zephir-lang.com/0.12/zh-cn/tutorial
cd /data/www/jsx/ zephir init utils touch /data/www/jsx/utils/utils/greeting.zep vim /data/www/jsx/utils/utils/greeting.zep #----------- 文件内容 namespace Utils; class Greeting { public static function say() { echo "hello world!"; } } #----------- 文件内容 cd /data/www/jsx/utils zephir build Zephir version has changed, use "zephir fullclean" to perform a full clean of the project Zephir version has changed, use "zephir fullclean" to perform a full clean of the project Preparing for PHP compilation... Preparing configuration file... Compiling... Zephir version has changed, use "zephir fullclean" to perform a full clean of the project Installing... Extension installed. Add "extension=utils.so" to your php.ini ! [NOTE] Don't forget to restart your web server