首页 > 代码库 > Phalcon 我们的动机(Our motivation)

Phalcon 我们的动机(Our motivation)

There are many PHP frameworks nowadays, but none of them is like Phalcon (Really, trust us on this one).

Almost all programmers prefer to use a framework. This is primarily because it provides a lot of functionality that is already tested and ready to use, therefore keeping code DRY (Don’t Repeat Yourself). However, the framework itself demands a lot of file inclusions and hundreds of lines of code to be interpreted and executed on each request from the actual application. Object-Oriented frameworks also add a lot of overhead to execution making complex application slow. All these operations slows the application down and subsequently impacts the end user experience.

现今有非常多的PHP框架,但是没有任何一个框架如Phalcon一样(这一点可以完全相信我们!)。几乎所有的程序员都倾向于使用框架。主要是因为框架提供给了我们非常多的易用的经常了检验的功能,基于此使用框架可以使我们的代码看上去更整洁(不要重复)。不过框架本身需求引入非常多的方文件,这样在应用中每次请示中要解析和执行的代码数以千行记。面象对象的框架也会有一些额外的开销这样做使一些复杂的程序变得更慢。所有这些操作会使用程序的执行慢下来最终会影响到终端用于的使用体验。

问题(The Question)?

Why can’t we have a robust framework with all of its advantages but with none or very few disadvantages?

This is why Phalcon was born!

During the last few months, we have extensively researched PHP’s behavior, investigating areas for significant optimizations (big or small). Through this understanding, we managed to remove unnecessary validations, compacted code, performed optimizations and generated low-level solutions so as to achieve maximum performance from Phalcon.

为什么我们不能做这样一个健壮的框架,这个框架拥有非常多的优点非常少的缺点?这就是Phalcon产生的原因。在过去的几个月里,我们深入的研究了PHP的行为, 主要集中在性能方面的研究。通过这次的深入的研究,我们去除不必要的验证,精减了代码,提供了性能,实现了更底层的解决方案这让我们的框架有了更在的性能提升。


为什么?(Why?)?

?The use of frameworks has become mandatory in professional development with PHP

?Frameworks offer a structured philosophy to easily maintain projects writing less code and making work more fun

?We love PHP and we think it can be used to create larger and more ambitious projects

使用Php框架在专业的PHP开发中已经成为必须的了。

框架提供了结构化的方法用以维护项目,使得我们可以写更少的代码使我们的工作更有趣

我们爱PHP我们想使用她创建更大的更伟大的项目。

PHP 内部是如何运作的?(Inner workings of PHP?)?

?PHP has dynamic and weak variable types. Every time a binary operation is made (ex. 2 + “2”), PHP checks the operand types to perform potential conversions

?PHP is interpreted and not compiled. The major disadvantage is performance loss

?Every time a script is requested it must be first interpreted

?If a bytecode cache (like APC) isn’t used, syntax checking is performed every time for every file in the request

PHP是弱类型的语言。每次双目操作在执行时(如 2+”2”),PHP会检查操作类型然后执行必要的转换

PHP是解释型语言而非编译型。最大的缺点即是性能损失(这也是所有解释型语言的缺点)。

每当一个请求一个脚本时,这个脚本首先要进行解释(解析)

如果字节码缓存(如APC, OPCache等)未启用,语法检查会在每次请求的每个所使用到的文件中进行

传统的 PHP 框架如何工作?(How do traditional PHP frameworks work?)?

?Many files with classes and functions are read on every request made. Disk reading is expensive in terms of performance, especially when the file structure includes deep folders

?Modern frameworks use lazy loading (autoload) to increase performance (for load and execute only the code needed)

?Some of these classes contain methods that aren’t used in every request but they’re loaded always consuming memory

?Continuous loading or interpreting is expensive and impacts performance

?The framework code does not change very often, and yet an application needs to load and interpret it every time a request is made

每次请示中许多文件中的类和方法都被加载到内存中。由此可以看出磁盘读取即是一个瓶颈,尤其是文件路径比较深时。

现今的许多框架都会使用lazy loading(autoload)技术以提升框架性能(只在需要时才加载)

这些类中包含的方法并不是在每次请示时都需要的,这些函数占用了不必要的内存。

持续的加载和解析的代价是比较大的,这会非常影响性能

框架的代码改变的不会非常频繁,不过每次在执行时程序依然会被加载和解释

PHP C扩展如何工作?(How does a PHP C-extension work?)?

?C extensions are loaded together with PHP one time on the web server’s daemon start process

?Classes and functions provided by the extension are ready to use for any application

?The code isn’t interpreted because is already compiled to a specific platform and processor

每次web服务器的服务进程在启动时C扩展都会和服务器一起加载

任何应用都可以使用这些扩展所提供的类和方法

扩展组件的代码不会被解释,因为他们被编译成了特定平台的代码

Phalcon 如何工作?(How does Phalcon work?)?

?Components are loosely coupled. With Phalcon, nothing is imposed on you: you’re free to use the full framework, or just some parts of it as a glue components.

?Low-level optimizations provides the lowest overhead for MVC-based applications

?Interact with databases with maximum performance by using a C-language ORM for PHP

?Phalcon directly accesses internal PHP structures optimizing execution in that way as well

组件是松耦合的。在Phalcon中任何东西都不是强制的: 你可以自由的使用框架的全部功能,或是只使用其中的一小部分功能

底层的优化策略使得我们的MVC程序程序有更小的开销

使用C语言书写的ORM框架可以为我们的数据库交互提供了更高的性能

Phalcon会直接的访问PHP内部结构这也使得程序的性能更优

为什么需要 Phalcon?(Why do I need Phalcon?)?

Each application requirements and tasks are different than another’s. Some for instance are designed to do a set of tasks and generate content that rarely changes. These applications can be created with any programming language or framework. Using a front-end cache usually makes such an application, no matter how poorly designed or slow it might be, perform very fast.

Other applications generate content almost immediately that changes from request to request. In this case, PHP is used to address all requests and generate the content. These applications can be APIs, discussion forums with high traffic loads, blogs with a high number of comments and contributors, statistic applications, admin dashboards, enterprise resource planners (ERP), business-intelligence software dealing with real time data and more.

An application will be as slow as its slowest component/process. Phalcon offers a very fast yet feature rich framework that allows developers to concentrate on making their applications/code faster. Following proper coding processes, Phalcon can deliver a lot more functionality/requests with less memory consumption and processing cycles.

每个程序的需求和任务是不同的。一些程序设计为执行一些任务然后产生一些很少改变的内容。这些应用可以使用任何语言和框架进行开发。

在程序中使用一个前端缓存,不管设计做的多烂都没关系,性能会非常好。


另外的应用可能产生的内容在每次请求时会不同。这种情况下,PHP会处理所有的请求然后产生结果。这些程序可能是软件系统的API,大流量的论坛, 拥有大量用户和留言量的博客系统,统计程序,管理面板, ERP系统,处理实时信息的商业软件等。

应用会像他们的组成组件一样非常慢。Phalcon即提供一个快速的多功能的框架,使用这个框架开发者可以组建出更高性能的应用。

遵循适当的编码处理方式 ,Phalcon可以提供更高的性能并且使用更少的内存。

结束语(Conclusion)?

Phalcon is an effort to build the fastest framework for PHP. You now have an even easier and robust way to develop applications with a framework implemented with the philosophy “Performance Really Matters”! Enjoy!

Phalcon致力于创建更高性能的PHP框架。我们现在有了一种方便快捷,可靠的方式创建应用程序,而且还是非常高性能的方式。享受Phalcon之旅吧。

Phalcon 我们的动机(Our motivation)