phalcon

tech2023-10-01  106

phalcon

I’ve written about Phalcon before, and we’ve got a variety of articles on the framework published already, which is apparent if you just visit the Phalcon category. In fact, not so long ago, I wrote about Zephir, Phalcon’s noble initiative to make building PHP extensions accessible to everyone.

之前,我已经写过有关Phalcon的文章,并且已经发布了有关该框架的各种文章,如果您只是访问Phalcon类别 ,这是显而易见的。 实际上,不久前,我写了有关Zephir的文章 ,这是Phalcon的崇高倡议,旨在使所有人都能访问构建PHP扩展。

Today, a new milestone has been reached by the team, and one that definitely warrants discussion. Way ahead of time, the Phalcon team announced the imminent release of Phalcon 2.0 alpha 1.

今天,团队已经达到了一个新的里程碑,而且绝对值得讨论。 Phalcon团队提前宣布即将发布Phalcon 2.0 alpha 1 。

猎鹰2 (Phalcon 2)

Phalcon 2 is a full rewrite of the original Phalcon Framework, in their new language, Zephir. As previously discussed, Zephir is a mixed-type derivative of PHP (both static and dynamic types are supported) which allows developers to write “almost-PHP” code and compile it down to C based extensions for PHP, installable like any other (iconv, imap, imagick, etc). Phalcon 2 was built almost entirely in this language, and is now easier than ever to maintain, update and above all – accept contributions from the community. As proof of working concept, the Phalcon team is running their site on Phalcon 2 here.

Phalcon 2以其新语言Zephir完全重写了原始Phalcon框架。 正如前面所讨论的 ,ZEPHIR是PHP(静态和动态类型的支持),它允许开发者写“几乎PHP”代码和编译它下降到C基扩展PHP的混合型衍生物,安装像任何其他(的iconv ,imap,imagick等)。 Phalcon 2几乎完全是用这种语言构建的,现在比以往任何时候都更易于维护,更新,最重要的是-接受社区的贡献。 作为工作理念的证明,Phalcon团队正在此处的 Phalcon 2上运行其站点。

Phalcon 2.0 is being brought up to speed with the current version 1.3 (it introduced some optimizations not present and yet required in 2.0), and is being built around existing 1.3 classes to ensure backwards compatibility. To see which classes were ported so far, observe the following table. If you’d like to assist in the transfers, submit a pull request as you see fit – particularly unit tests. Most of the ported components simply haven’t been tested yet, even after being fully developed.

Phalcon 2.0正在与当前版本1.3(它引入了一些尚不存在但2.0中尚需的优化)一起加快发展,并围绕现有的1.3类进行构建以确保向后兼容。 要查看到目前为止已移植了哪些类,请观察下表 。 如果您想协助转移,请提交您认为合适的请求-特别是单元测试。 甚至在完全开发之后,大多数移植的组件都尚未经过测试。

Zephir和创建扩展 (Zephir and creating extensions)

Zephir is now in version 0.3, and can be used by the general public to write custom extensions for PHP. Zephir supports all the standard logical structures you’re used to (except “else if”), and lets you pre-declare variables by type to make it easier to compile into highly optimized C code. It’s important to note that Zephir is an ahead-of-time compilation language, meaning the compilation step might just make you less productive if you’re used to iterating and testing rapidly. The long term gains, however, are worth it.

Zephir现在的版本为0.3,可以被公众用来编写PHP的自定义扩展。 Zephir支持您习惯的所有标准逻辑结构(“ else if”除外),并允许您按类型预先声明变量,以使其更易于编译为高度优化的C代码。 需要特别注意的是Zephir是一种提前编译的语言,这意味着如果您习惯于快速迭代和测试,则编译步骤可能会使您的工作效率降低。 但是,长期的收益是值得的。

Zephir is memory-safe, meaning it has no pointers or manual memory management support. For such low level operations, one should stick with C. With regards to power, Zephir is thus weaker, but more user friendly than C. You can consider it a hybird of C and PHP, leaning more to the PHP side of things.

Zephir是内存安全的,这意味着它没有指针或手动内存管理支持。 对于这样的低级操作,应该坚持使用C。就功率而言,Zephir较弱,但比C更用户友好。您可以将其视为C和PHP的混合体,更多地倾向于PHP方面。

So what can I do with it? Always wanted to close-source your PHP app? Wondered how much faster a statistics calculation of your company’s backend would be if it were running in C? You can do all that and more now. First, check out this Vimeo screencast on making your first Zephir extension.

那我该怎么办呢? 一直想关闭您PHP应用程序的源代码? 想知道如果您的公司的后端运行在C语言中,那么进行后端统计的速度会快多少? 您现在可以做更多的事情。 首先,查看有关制作您的第一个Zephir扩展的Vimeo截屏视频。

Creating your first PHP extension with Zephir from Phalcon Framework on Vimeo.

从Vimeo上的Phalcon Framework 使用Zephir创建您的第一个PHP扩展 。

Next, follow through the tutorial, read the docs, and play around. If you end up making anything other than what the tutorials teach, we’d love to publish your step-by-step.

接下来,按照教程进行操作 ,阅读文档 ,然后进行练习。 如果您最终无法完成教程所教的内容,那么我们很乐意逐步发布您的内容。

An example Hello World class like this one:

像这样的Hello World类示例:

namespace Test ; /** * This is a sample class */ class Hello { /** * This is a sample method */ public function say () { echo "Hello World!" ; } }

will compile down into this one:

将编译为以下内容:

#ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_test.h" #include "test.h" #include "kernel/main.h" /** * This is a sample class */ ZEPHIR_INIT_CLASS ( Test_Hello ) { ZEPHIR_REGISTER_CLASS ( Test , Hello , hello , test_hello_method_entry , 0 ); return SUCCESS ; } /** * This is a sample method */ PHP_METHOD ( Test_Hello , say ) { php_printf ( "%s" , "Hello World!" ); }

Note that Zephir requires you to use classes and namespaces – code without them is not allowed – this is to enforce good coding habits, proper object oriented code and solid encapsulation.

需要注意的是ZEPHIR需要您使用类和命名空间-没有他们的代码是不允许的-这是执行良好的编码习惯,适当的面向对象的代码和固体封装。

贡献 (Contributing)

You can contribute to the faster development and better test coverage of Phalcon 2.0 by installing as usual, only doing so from the 2.0.0. branch. Note that this will replace your current Phalcon installation – so only use it in development environments, preferably something like Vagrant boxes. For more details on pulling off a Phalcon install in a Vagrant VM, see this article.

通过照常安装(仅从2.0.0版本开始) ,您可以为Phalcon 2.0的更快开发和更好的测试覆盖率做出贡献。 分行 。 请注意,这将代替您当前的Phalcon安装-因此只能在开发环境中使用它,最好在Vagrant box之类的环境中使用。 有关在Vagrant VM中进行Phalcon安装的更多详细信息,请参阅本文 。

The full installation procedure is as follows:

完整的安装过程如下:

git clone http : //github.com/phalcon/cphalcon git checkout 2.0 . 0 cd ext sudo ./ install - test

In any *nix environment, this just clones the usual repo, switches to the 2.0.0 branch, and then installs as usual. The API is, for the most part, identical to what it was, so transitioning shouldn’t be very difficult – and if you encounter any bugs, the Phalcon team encourages bug reports on the GitHub issues page, preferably followed by Unit Tests that demonstrate the bugs. For a good overview of contributing to an open source project on GitHub, please see here and here.

在任何* nix环境中,这仅克隆通常的存储库,切换到2.0.0分支,然后照常安装。 该API在很大程度上与原来的API相同,因此过渡并不难-如果您遇到任何错误,Phalcon团队会鼓励在GitHub问题页面上报告错误,最好在此之后进行单元测试,以证明错误。 有关在GitHub上为开源项目做出贡献的良好概述,请参见此处和此处 。

To further contribute to Phalcon effortlessly, consider upvoting this issue as well – it aims to have Phalcon installed on Google App Engine, as described here, and would produce the most powerful PHP environment to date, outperforming even HHVM.

为了进一步促进尔康费力 ,考虑upvoting 这个问题以及-它的目的是安装在谷歌App Engine的尔康,如所描述这里 ,并会产生最强大PHP环境,到目前为止,跑赢甚至HHVM 。

结论 (Conclusion)

Phalcon is moving ahead faster and better than anyone expected. We can expect to see the full stable release by Q2 2014 for sure, marking a year of Zephir’s development and Phalcon2’s announcement. The framework will probably be safe to use in production apps long before that.

Phalcon的发展比任何人所预期的更快,更好。 我们可以肯定会在2014年第二季度看到完全稳定的发布,这标志着Zephir的发展和Phalcon2的发布。 在此之前,该框架很可能可以安全地用于生产应用程序中。

If you’re experimenting with Phalcon 2 or Zephir, please give us a shout – we’d love to publish some tutorials you write. If you just have an idea, or have built something but feel like you don’t write well or your English is bad, get in touch nonetheless – we’ll find a way.

如果您正在尝试使用Phalcon 2或Zephir,请大声疾呼-我们很乐意发布您编写的一些教程。 如果您只是有一个主意,或者已经建立了一些东西,但是感觉自己写的不好或英语不好,请保持联系-我们会找到一种方法。

翻译自: https://www.sitepoint.com/phalcon-2-0-alpha-landing/

phalcon

最新回复(0)