Table of Contents
回复内容:
Home Backend Development PHP Tutorial 国内C源码PHP框架选择与评价 Yaf Yar Swoole workerman?

国内C源码PHP框架选择与评价 Yaf Yar Swoole workerman?

Jun 17, 2016 am 08:31 AM
bat php swoole

对于韩天峰(Rango)的博客 《Yii/Yaf/Swoole 3个框架的压测性能对比》一文分析引起我作为一名 PHPer 的思考:如今PHP 的玩法越来越多,那么在大部分PHP开发中,大家是怎么看待这些框架的呢?而像BAT这些巨头类的企业,PHP开发方向他们是一个什么状态呢?

回复内容:

先放结论:
  1. 需要极致的性能,可以接受代码执行机制和一般的 LAMP 部署方式不一致: Swoole 或 Workerman,本机 ab 压测短连接都能达到1.9W+ requests/sec;
  2. 需要高性能,同时需要包括完整的 MVC 支持在内的全框架特性支持:Phalcon;
  3. 需要高性能,专注于实现,仅需要基础的 URL 路由:Yaf。
Swoole 的运行机制和其他所有框架都不一样,是完整的 FastCGI 模式,即不仅只去除了 Fork 的开销,还消灭了重复性的 init。 因此,也带来了开发时需要注意发布新版本必须重新 reload。 其配套框架似乎能解决此问题,但抱歉未深入研究。
Workerman 的核心要点和 Swoole 一致,但采用了纯 PHP 的 Web Socket 实现。和 Swoole 相比最大的好处是移除了对 C 扩展的需求,但必须采用 CLI 模式运行使其还是无法跑在虚拟主机上,但不管怎么说,起码客户端不需要依赖扩展了。
没有在生产环境中玩过以上两者,不过多评价。

Yaf 也提供了极高的性能,同时不改变原有的 PHPer 的知识架构,只是为了简洁放弃了 DB 有关的封装。但事实上这部分即重,又不是高度重复执行,确实没有必要在扩展层面实现,通过 Composer 随便装个 ORM/ActiveRecord 的包就可以了。 何况对于高性能网站的前端而言,大部分时候是不会允许去碰缓存外的东西的。
Phalcon 比起 Yaf 来说,框架特性和文档都要好很多,性能下降也并不多(仅1/10左右的差异)。
以上两者,一般来说我更推荐 Yaf,架构总是要有取舍的,认清楚 Yaf 没有像其他框架一样提供那么多舒心的特性是有原因的:别在要求高性能的场合玩那些有的没的。

所以,如果是修改较少的内部服务(比如SOA 架构中后端去除 View 了的 BLL 层),或是开放 API 系统之类,那么我推荐 Swoole / Workerman。
如果是团队不想经历较高的学习曲线(实际上面对高性能这个问题时,只有高、较高和非常高这几个选项吧?),那么就用 Yaf / Phalcon 吧。 Yaf Yar Swoole 这三个是C的扩展的框架,workerman应该是原生的PHP写的socket服务器框架。

我觉得这四个不管哪一款都是国内比较优秀的并且令人耳目一新的框架。这四款框架让我们了解到PHP不仅仅局限于做数据库的增删改查,还能实现更多重要的东西。

据我所知像BAT这类巨头企业中早已经有用原生PHP做服务器(类似workerman)类似的应用,而且有交大规模的应用和部署。 Baidu: HHVM,Yaf
阿里:主要用在Web前端
腾讯:以前是纯PHP写的Socket框架PSF,基本已经停用了,Swoole是未来的技术发展方向。 选择 C 源码类型的 PHP 框架的唯一理由是性能。 正在测试yaf框架和HHVM一起用,但不知扩展支持情况 PHP7出来了
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

See all articles