[收藏]PHP V5.3 中的新特性,使用 Phar 归档


Phar 归档的概念来自 Java™ 技术的 JAR 归档,它允许使用单个文件打包应用程序,这个文件中包含运行应用程序所需的所有东西。该文件不同于单个可执行文件,后者通常由编程语言生成,比如 C,因为该文件实际上是一个归档文件而非编译过的应用程序。因此 JAR 文件实际上包含组成应用程序的文件,但是考虑到安全性,不对这些文件进行仔细区分。Phar 扩展正是基于类似的理念,但是在设计时主要针对 PHP 的 Web 环境。同样,与 JAR 归档不同的是,Phar 归档可由 PHP 本身处理,因此不需要使用额外的工具来创建或使用。Phar 扩展对 PHP 来说并不是一个新鲜的概念。它最初使用 PHP 编写并被命名为 PHP_Archive,然后在 2005 年被添加到 PEAR 库。然而在实际中,解决这一问题的纯 PHP 解决方案非常缓慢,因此 2007 年重新编写为纯 C 语言扩展,同时添加了使用 SPL 的 ArrayAccess 对象遍历 Phar 归档的支持。自那时起,人们做了大量工作来改善 Phar 归档的性能。创建 Phar创 建 Phar 文件需要执行若干步骤。所有步骤需要用到某种形式的 PHP 命令完成创建,因为不存在用于创建归档的独立工具。此外,要创建和修改 Phar 文件,php.ini 设置 phar.readonly 必须被设置为 0。在 PHP 的 Phar 归档内打开和引用文件时不需要使用到该设置。让我们看一看创建可用于驱动应用程序的 Phar 文件需要哪些步骤。应用程序的设计目标是从 Web 浏览器或命令提示符直接加载。第一步是创建 Phar 文件,因此我们将创建清单 1 所示的 Phar 对象。对象引用将允许您控制 Phar 归档的所有方面。
创建 Phar 对象
  1. $p = new Phar('/path/to/my.phar', CURRENT_AS_FILEINFO | KEY_AS_FILENAME, 'my.phar');
  2. $p->
    ......

[收藏]深入理解PHP内核 (好文,收藏之)


目录

    第一章 准备工作和背景知识
        第一节 环境搭建
        第二节 源码布局及阅读方法
        第三节 常用代码
        第四节 小结

    第二章 概览
        第一节 生命周期及Zend引擎概览
        第二节 SAPI
            Apache模块
            嵌入式
            Fastcgi
        第三节 脚本的执行
            词法分析和语法分析
            opcode
            附:找到Opcode具体实现
        第四节 小结

    第三章 变量及数据类型
        第一节 变量的内部结构
            哈希表(HashTable)
            PHP的哈希表实现
        第二节 常量
        第三节 预定义变量
        第四节 静态变量
        第五节 类型提示的实现
        第六节 变量的生命周期
            变量的赋值和销毁
            变量的作用域
            global语句
        第七节 数据类型转换
     &n
......

Web站点性能优化


Minimize HTTP Requests
tag: content80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.One way to reduce the number of components in the page is to simplify the page's design. But is there a way to build pages with richer content while also achieving fast response times? Here are some techniques for reducing the number of HTTP requests, while still supporting rich page designs.Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet. Combining files is more challenging when the scripts and stylesheets vary from page to page, but making this part of your release process improves response times.CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.Image maps combine multiple images into a single image. The overall size is about the same, but reducing the number of HTTP requests speeds up the page. Image maps only work if the images are contiguous in the page, such as a navigation bar. Defining the coordinates of image maps can be tedious and error prone. Using image maps for navigation is not accessible too, so it's not recommended.Inline images use the data: URL scheme to embed the image da
......

    Search On Site