zephir 编译php,Zephir:用于开发PHP扩展,且介于PHP和C++之间的编译语言

394643ffc023b22794f07b6096c3d335.png Zephir

68747470733a2f2f706f7365722e707567782e6f72672f7068616c636f6e2f7a65706869722f762f737461626c652e706e6768747470733a2f2f706f7365722e707567782e6f72672f7068616c636f6e2f7a65706869722f646f776e6c6f6164732e706e6768747470733a2f2f706f7365722e707567782e6f72672f7068616c636f6e2f7a65706869722f6c6963656e73652e73766768747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068616c636f6e2f7a65706869722f6d61737465722e73766768747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f637861313831306d643776366e3039353f7376673d74727565

Zephir - Ze(nd Engine) Ph(p) I(nt)r(mediate) - is a high level language that eases the creation and maintainability of extensions for PHP. Zephir extensions are exported to C code that can be compiled and optimized by major C compilers such as gcc/clang/vc++. Functionality is exposed to the PHP language.

Main features:

Both dynamic/static typing

Reduced execution overhead compared with full interpretation

Restricted procedural programming, promoting OOP

Memory safety

Ahead-of-time (AOT) compiler to provide predictable performance

Compiler design goals:

Multi-pass compilation

Type speculation/inference

Allow runtime profile-guided optimizations, pseudo-constant propagation and indirect/virtual function inlining

Requirements

re2c >= 0.13.6

A C compiler such as gcc >= 4.4 or an alternative such as clang >= 3.0, Visual C++ >= 11 or Intel C++. It is recommended to use gcc 4.4 or later

GNU make >= 3.81

automake

PHP development headers and tools

The build-essential package when using gcc on Ubuntu (and likely other distros as well)

Installation

NOTE: The development branch will always contain the latest unstable version. If you wish to check older versions or formal, tagged release, please switch to the relevant branch/tag.

Windows

To install Zephir on Windows follow this guide.

Linux | macOS | BSD | Solaris

Git way

Clone Zephir repository.

Then, install Zephir by using command ./install from project root dir. For global installation add -c flag.

Composer way

You can install Zephir using composer.

To get Zephir, run composer require phalcon/zephir.

Additional notes on Ubuntu

The following packages are needed in Ubuntu:

apt-get install re2c libpcre3-dev

Usage

Compile the extension:

zephir compile

External Links

Contributing

See CONTRIBUTING.md for details about contributions to this repository.

License

Zephir is open-sourced software licensed under the MIT License. See the LICENSE file for more information.

好的,下面是一个使用 Zephir 编写的简单的 PHP 扩展示例: 1. 首先,创建一个名为 `hello` 的文件夹,该文件夹包含以下内容: ``` hello/ ├── ext/ │ └── config.m4 │ └── hello.zep │ └── php_hello.h ├── hello.php └── php.ini ``` 2. 在 `ext` 目录下创建一个名为 `config.m4` 的文件,并将以下内容添加到该文件中: ```m4 PHP_ARG_ENABLE(hello, whether to enable Hello support, [ --enable-hello Enable Hello support]) if test "$PHP_HELLO" = "yes"; then PHP_SUBST(HELLO_SHARED_LIBADD) PHP_NEW_EXTENSION(hello, hello.zep, $ext_shared) fi ``` 3. 在 `ext` 目录下创建一个名为 `hello.zep` 的文件,并将以下内容添加到该文件中: ```zephir namespace Hello; function sayHello() -> void { echo "Hello, world!"; } ``` 4. 在 `ext` 目录下创建一个名为 `php_hello.h` 的文件,并将以下内容添加到该文件中: ```c #ifndef PHP_HELLO_H #define PHP_HELLO_H 1 #include "php.h" extern zend_module_entry hello_module_entry; #define phpext_hello_ptr &hello_module_entry #endif ``` 5. 在 `hello` 目录下创建一个名为 `hello.php` 的文件,并将以下内容添加到该文件中: ```php <?php if (!extension_loaded('hello')) { dl('hello.' . PHP_SHLIB_SUFFIX); } Hello\sayHello(); ``` 6. 在 `hello` 目录下创建一个名为 `php.ini` 的文件,并将以下内容添加到该文件中: ```ini extension=hello ``` 7. 在命令行中导航到 `hello/ext` 目录,并运行以下命令来编译并安装扩展: ``` zephir build sudo make install ``` 8. 在命令行中导航到 `hello` 目录,并运行以下命令来运行 PHP 脚本: ``` php hello.php ``` 输出应该是 `Hello, world!`。 这是一个非常简单的示例,但它可以让您了解如何使用 Zephir 编写 PHP 扩展。您可以使用更复杂的代码来构建更高级的扩展
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值