tsung: 好文: PHP performance tips - Google Webmaster

标签: tsung php performance | 发表时间:2011-06-07 01:34 | 作者:(author unknown) 小汐
出处:http://planet.debian.org.tw/

Google 提供的 PHP 效能調校(Optimize performance)的幾點原則, 詳細可見此文:

PHP 效能最佳化

此文內容很短, 講得都是大方向, 主題內容如下:

  • Profile your code to pinpoint bottlenecks
  • 升級 PHP 的版本
  • Use caching - 使用 Memcache, 若有使用 Template, 也要有支援 Template cache, ex: Smarty
  • Use output buffering
    • 我自己的心得: 提早讓使用者看到內容, 不過以目前流行的 MVC 架構來說, 這個得要在做些改變, 應該要改成 MVP 架構比較合適.
  • Avoid writing naive setters and getters
    • 物件若再包一層 setName()、getName(), 會比直接 $x->name 慢上一倍 - 可見此範例: #638732 - Pastie
  • Don't copy variables for no reason
    • if a user had inserted 512KB worth of characters into a textarea field. This implementation would result in nearly 1MB of memory being used.
    • 若沒有特別理由, 不要在多增加變數, ex:
      • $description = strip_tags($_POST['description']);
      • echo $description;
    • 請直接
      • echo strip_tags($_POST['description']);
  • Avoid doing SQL queries within a loop
    • 避免讓 SQL 放在迴圈中, ex:
      • foreach ($userList as $user) {
        $query = 'INSERT INTO users (first_name,last_name) VALUES("' . $user['first_name'] . '", "' . $user['last_name'] . '")';
        mysql_query($query);
        }
    • 上述程式會執行的語法:
      • INSERT INTO users (first_name,last_name) VALUES("John", "Doe");
    • 建議改用:
      • $userData = array();
        foreach ($userList as $user) {
        $userData[] = '("' . $user['first_name'] . '", "' . $user['last_name'] . '")';
        }
        $query = 'INSERT INTO users (first_name,last_name) VALUES' . implode(',', $userData);
        mysql_query($query);
    • 上述程式會執行的語法: (先把要寫入的先都組起來, 在一併丟入 MySQL 執行)
      • INSERT INTO users (first_name,last_name) VALUES("John", "Doe"),("Jane", "Doe")...
    • 詳細可見: MySQL INSERT Syntax

相关 [tsung php performance] 推荐:

tsung: 好文: PHP performance tips - Google Webmaster

- 小汐 - Planet DebianTW
Google 提供的 PHP 效能調校(Optimize performance)的幾點原則, 詳細可見此文:. 原文: Let's make the web faster - PHP performance tips. 作者: Eric Higgins, Google Webmaster. 此文內容很短, 講得都是大方向, 主題內容如下:.

MySQL的Performance Schema库

- - 数据库 - ITeye博客
Performance Schema是MySQL自带的、较为底层的性能监控特性,提供一系列、具备自定义收集粒度的监控体系. 对MySQL服务执行过程中的各项事件(Events)的分析尤为重视. Performance Schema的精细化控制,主要通过performance_schema库下的一系列setup表来实现.

Elasticsearch Performance Tuning Practice at eBay

- -
Elasticsearch is an open source search and analytic engine based on Apache Lucene that allows users to store, search, analyze data in near real time. This document summarizes the challenges as well as the process and tools that the Pronto team builds to address the challenges in a strategic way.

译|High-Performance Server Architecture

- - 掘金 架构
本文的目的是分享我多年来关于如何开发某种应用程序的一些想法,对于这种应用程序,术语“服务”只是一个无力的近似称呼. 更准确地说,将写的与一大类程序有关,这些程序旨每秒处理大量离散的消息或请求. 网络服务通常最适合此定义,但从某种意义上讲,实际上并非所有的程序都是服务. 但是,由于“高性能请求处理程序”是很糟糕的标题,为简单起见,倒不如叫“服务”万事大吉.

ORACLE SQL Performance Analyzer的使用

- - CSDN博客数据库推荐文章
通过 SPA,您可以根据各种更改类型(如初始化参数更改、优化器统计刷新和数据库升级)播放特定的. SQL 或整个 SQL 负载,然后生成比较报告,帮助您评估它们的影响.. 在 Oracle Database 11g 之前的版本中,我必须捕获所有 SQL 语句,通过跟踪运行这些语句,. 然后得到执行计划 — 这是一项极其耗时又极易出错的任务.

XMPP、HTTP 模拟压力测试工具 Tsung 教程

- - CSDN博客推荐文章
由于需要erlang支持,那么下载erlang-R14B04. 使用该脚本测试的时候,要禁用XMPP服务器的auth验证模块,不然账号密码不对,登陆不进去. 单个IP的端口65535的问题导致单个机器模拟的连接数有限,这个问题我没解决,只能通过使用很多机器都开这个服务来解决. 作者:smm11230704 发表于2012-4-17 3:21:36 原文链接.

PHP导出excel

- syeye - scofield PHP开发-SEO SEM
最近做一个项目,其中涉及到了数据导成excel的功能. 后来使用了 开源的 PHPExcel  http://phpexcel.codeplex.com/ 目前最新版是1.7.6. PHPExcel 可以生成 .xls 和 .xlsx (office2007). 比如设置 excel的title,keywords,description.

PHP框架 Yaf

- Le - 开源中国社区最新软件
Yaf是一个C语言编写的PHP框架,Yaf 的特点: 用C语言开发的PHP框架, 相比原生的PHP, 几乎不会带来额外的性能开销. 所有的框架类, 不需要编译, 在PHP启动的时候加载, 并常驻内存. 更短的内存周转周期, 提高内存利用率, 降低内存占用率. 支持全局和局部两种加载规则, 方便类库共享.

SQL Performance Analyzer SPA常用脚本汇总

- - CSDN博客数据库推荐文章
附件为 一个SPA报告  spa_buffergets_summary. SQL 性能分析器 SQL Performance Analyzer SPA. Oracle Database 11g 引入了 SQL 性能分析器;使用该工具可以准确地评估更改对组成工作量的 SQL 语句的影响. SQL 性能分析器可帮助预测潜在的更改对 SQL 查询工作量的性能影响.

使用performance api监测页面性能

- - jackyrong
对于前端开发来说,知道整个页面从开始加载到有内容展示出来的时间是很重要的事情. 通常我们要知道页面加载的时间的话.是采用计算几个关键的时间点的方法来得出页面加载的时间.但是这个方式存在一些问题,比如:我们不知道浏览器在开始解析页面之前卸载前一个文档,解析dns的时间. 那么performance API是啥,能做啥和不能做啥呢.