当前位置: 首页 > 工具软件 > Zephir > 使用案例 >

window zephir_Zephir-在不了解C的情况下构建PHP扩展

卢杰
2023-12-01

window zephir

Due to PHP being written in C, for a long time now the only way to extend it was to either rely on the current generation of enthusiastic greybeards, or take up C. For many, the latter wasn't an option. We, the high level developers of today, are far too lazy to take up such a wonderfully precise, demanding, low level, OCD-centric language. Most of us who began our programming careers in high level languages – especially high level languages that are, to be honest, hacks on hacks on hacks like Javascript and PHP – are quite frankly completely disinterested in learning all the magic C asks of you. This is not to say we're worse developers than the ones dealing with low levels exclusively – it's just two different worlds – we simply love the instant gratification of web development. It would take me just as long to waddle through an intermediate C program as it would an experienced low level developer to develop a pretty cross-browser compatible JS radial context menu. So how, then, is a PHP developer supposed to enrich PHP itself with much needed functionality?

由于PHP是用C编写的,因此很长一段时间以来,扩展它的唯一方法是要么依赖当前一代的热情的胡子,要么使用C。对于许多人而言,后者是不可取的。 我们,当今的高级开发人员,实在太懒惰了,无法采用如此精确,苛刻,低级,以OCD为中心的语言。 坦率地说,我们大多数人是从高级语言开始编程职业的,尤其是高级语言,老实说,黑客攻击了诸如Javascript和PHP之类的黑客,但坦率地说,他们完全没兴趣学习C所要求的一切。 这并不是说我们比专门处理低级别的开发人员要糟糕(这只是两个不同的世界),我们只是喜欢即时满足Web开发的需求。 我需要花很长时间才能完成一个中间C程序,就像花一个经验丰富的低级开发人员来开发一个与跨浏览器兼容的JS径向上下文菜单一样。 那么,PHP开发人员应该如何利用急需的功能来丰富PHP本身呢?

hal (Phalcon)

A while back, I mentioned the Phalcon framework in an article. Phalcon is a framework that offers more than most of the current frameworks, but is wrapped up as a PHP extension you install like IMAP, iconv, mcrypt or any other. I won't go into details right now, the links above provide plenty information, but what's important here is the magnitude of the milestone the Phalcon team achieved.

前一段时间,我在一篇文章中提到了Phalcon框架。 Phalcon是一个框架,提供了比大多数当前框架更多的框架,但作为您安装PHP扩展(如IMAP,iconv,mcrypt或其他任何一个)包装。 我现在不再赘述,上面的链接提供了大量信息,但是这里重要的是Phalcon团队实现的里程碑的规模。

Phalcon is a wonderful hybrid created by wonderful hybrids

Phalcon是由出色的混合动力车创造的出色混合动力车

Phalcon is a wonderful hybrid created by wonderful hybrids – people who are excellent at both PHP and C. Phalcon is the golden middle ground, a PHP framework that's as low level as it gets (immeasurable performance gains when compared to other frameworks) but its API still high level enough for any experienced PHP developer to use just like in any other framework.

Phalcon是由出色的混合动力创建的出色混合动力-精通PHP和C的人。Phalcon是黄金的中间地带,一个PHP框架虽然水平不高(但与其他框架相比性能无法衡量),但其API仍然足够高的水平,任何经验丰富PHP开发人员都可以像在其他任何框架中一样使用。

So what is Zephir and what does it have to do with Phalcon? As it turns out, the developers of Phalcon realized pull requests to a C project like Phalcon are coming in far too slowly when compared to the speed of growth in Phalcon's popularity – in no small part due to the rarity of high quality open-source oriented C developers. Fearing a bottleneck, they undertook another adventure that's poised to redefine the world of PHP development as we know it. They decided to build Zephir.

那么Zephir是什么?它与Phalcon有什么关系? 事实证明,与Phalcon受欢迎程度的增长速度相比 ,Phalcon的开发人员意识到对像Phalcon这样的C项目的拉取请求太慢了 -很大程度上是由于面向高质量开源的稀有性C开发人员。 由于担心瓶颈,他们进行了另一场冒险,准备重新定义PHP开发的世界。 他们决定建造Zephir。

Zephir? (Zephir?)

If Phalcon is the golden middle ground between C and PHP, Zephir is platinum. Zephir will be (note I'm saying will be because it's still in very early alpha stages) the only language that lets high level developers develop low level PHP extensions.

如果说Phalcon是C和PHP之间的黄金中间地带,那么Zephir就是白金。 Zephir将成为(允许我说这是因为它仍处于非常早期的alpha阶段)唯一一种允许高级开发人员开发低级PHP扩展的语言

Zephir lets high level developers make low level PHP extensions

Zephir使高级开发人员可以进行低级PHP扩展

Zephir will be a static/dynamic typed language that compiles into C. It will have automatic memory management and will enforce strict and explicit over flexible and implicit behavior. The aim is to hide unnecessary C complexity from developers, make the code more debuggable, and produce object oriented libraries that can be used directly in PHP just like any other installable extension. The Phalcon team is currently rewriting the entire Phalcon framework in Zephir, gearing up for version 2.0, which will allow the huge pool of PHP devs using Phalcon to extend it without knowing C.

Zephir将是一种静态/动态类型的语言,可以编译成C语言。它将具有自动内存管理功能,并将对柔性和隐式行为强制执行严格和显式的操作。 目的是向开发人员隐藏不必要的C复杂性,使代码更易于调试,并生成可以与任何其他可安装扩展一样直接在PHP中使用的面向对象的库。 Phalcon团队目前正在用Zephir重写整个Phalcon框架,以适应版本2.0,这将允许大量使用PhalconPHP开发人员在不了解C的情况下对其进行扩展。

In addition to being used to develop and maintain Phalcon, Zephir is already in use elsewhere. The Apigility project by the Zend team will be integrating Zephir in order to allow users to improve performance of the APIs built with Apigility. What's more, knowing Zephir will have the additional benefit of allowing you to write your entire web app in it, compile it to C, and install it into your client's servers without exposing your code to anyone. Zephir is taking code protection, PHP app performance and development of PHP extensions to entirely new levels.

除了用于开发和维护Phalcon,Zephir还已在其他地方使用。 Zend团队的Apigility项目将集成Zephir,以允许用户提高使用Apigility构建的API的性能。 而且,了解Zephir还会带来其他好处,即允许您在其中编写整个Web应用程序,将其编译为C,然后将其安装到客户端服务器中而无需将代码暴露给任何人。 Zephir正在将代码保护,PHP应用程序性能以及PHP扩展的开发提升到全新的水平。

Zephir lets you truly close the source of your PHP application, protecting your intellectual property

Zephir使您可以真正关闭PHP应用程序的源代码,从而保护您的知识产权

It's important to note that Zephir is not a replacement for any current web language. It's not a replacement for C either. It's a gateway between C and PHP, allowing you to write high performance PHP extensions and closed-source PHP apps without the headaches and timewastage of a C development cycle. It will neither replicate all of PHP's functionality, nor all of C's functionality – it's not intended as an alternative to either. In fact, not every app should be rewritten with Zephir, as it might turn out to be nothing but a waste of time – the apps that should be rewritten are, for example, those you care about close-sourcing, and those that are computationally too intensive for the PHP interpreter. Rewriting something like WordPress in Zephir, for example, would be a fool's errand because WordPress is a huge yarn of low quality spaghetti code, and more would be gained by rewriting it to proper, modern object oriented PHP5.5.

需要特别注意的是Zephir不能替代任何当前的网络语言。 它也不是C的替代品。 它是C和PHP之间的网关,使您可以编写高性能PHP扩展和封闭源代码PHP应用程序,而无需担心C开发周期的麻烦和时间。 它既不会复制PHP的所有功能,也不会复制C的所有功能–不能替代任何一种。 实际上,并不是每个应用程序都应该用Zephir进行重写,因为事实证明,这仅仅是浪费时间–例如,应该重写的应用程序是您关心紧密采购的应用程序,以及那些在计算上需要计算的应用程序对于PHP解释器而言过于密集。 例如,用Zephir重写WordPress之类的东西是愚蠢的,因为WordPress是低质量的意大利面条代码的巨大组成部分,并且通过将其重写为适当的,现代的面向对象PHP5.5可以获得更多收益。

有代码示例吗? Phalcon的表现如何? (Are there any code samples? What about Phalcon's performance?)

There are some examples here and in the documentation. Essentially, it's quite similar to the languages you already know – Javascript, PHP, maybe even C, making Zephir an ideal candidate to pick up and try out quickly.

这里文档中都有一些示例。 从本质上讲,它与您已经知道的语言非常相似-Javascript,PHP甚至C语言,使Zephir成为快速尝试的理想选择。

Now, many wonder about the performance impact. If Phalcon is so fast due to it being written in C, won't rewriting it in a higher level language slow it down? Well, yes and no. While it won't allow the developers to dive into the nitty gritty of manual memory space allocation and whatnot, it will allow them to work faster, which will in turn let them iterate more rapidly and improve the design rather than improving only existing implementation. Naturally, some parts will remain written in C simply because there's just no way to rewrite them and keep their quality.

现在,许多人对性能影响感到疑惑。 如果Phalcon由于用C编写而是如此之快,难道不会用高级语言重写它会减慢它的速度吗? 好吧,是的,不是。 尽管它不允许开发人员深入了解手动内存空间分配的精髓,但可以使他们更快地工作,从而使他们可以更快地迭代并改善设计,而不是仅仅改善现有的实现。 自然地,仅由于无法重写它们并保持其质量,某些部分仍将保留用C编写。

Some initial benchmarks of Phalcon's current implementation versus its Zephir version can be found here.

此处可以找到有关Phalcon当前实现与其Zephir版本的一些初始基准测试。

今天尝试Zephir (Trying Zephir today)

To try Zephir for yourself (or, if you're an amazing C developer and you'd like to help) you can check out the Github repository. From there, you can also download, build and install the language – just follow the README instructions. Preliminary documentation can be found on the Zephir project home page and their blog is available as well. For those using TextMate or Sublime Text, a syntax highlighter can be found here.

要亲自尝试Zephir(或者,如果您是一位了不起的C开发人员,并且想提供帮助),可以查看Github存储库 。 从那里,您还可以下载,构建和安装该语言-只需按照README说明进行操作即可。 初步文档可以在ZEPHIR项目上找到的主页和他们的博客是可以作为很好 。 对于使用TextMate或Sublime Text的用户,可以在此处找到语法突出显示器。

Give Phalcon and Zephir a go, and let us know in the comments below how you like them. If you try out Zephir and develop an extension with it, feel free to drop me a line about turning it into a tutorial.

试一下Phalcon和Zephir,并在下面的评论中告诉我们您的喜好。 如果您试用Zephir并开发它的扩展,请随意给我讲有关将其转变为教程的内容。

结论 (Conclusion)

If you've always wanted to improve PHP on your own, but never took up C properly to do so, Zephir is for you. If you want to protect your code from prying eyes and piracy, just improve performance of your apps, or extend PHP with functionality that can't be effectively replicated through PHP itself, Zephir is for you.

如果您一直想自己改进PHP,但从未适当使用C语言,那么Zephir适合您。 如果您想保护代码免遭窥视和盗版,只是提高应用程序的性能,或者使用无法通过PHP本身有效复制的功能扩展PHP,则Zephir适合您。

I hope you enojyed this brief overview of this promising new project, and that you're as excited as we are about the benefits it could bring.

我希望您对这个有前途的新项目作了简短的概述,并希望我们为它带来的好处感到兴奋。

翻译自: https://www.sitepoint.com/zephir-build-php-extensions-without-knowing-c/

window zephir

 类似资料: