开发者社区> 问答> 正文

PHP编译原理解析? 400 报错

PHP编译原理解析? 400 报错


最近要给Yahoo的同事们做一个关于PHP和Apache处理请求的内部机制的讲座,刚好写了些关于Opcodes的文字,就发上来了,这个文章基于 Sara Golemon大师的《Understanding OPcode》

Opcode是一种PHP脚本编译后的中间语言,就像Java的ByteCode,或者.NET的MSL,举个例子,比如你写下了如下的PHP代码:

1
2
3
4
5
<?php
   echo "Hello World" ;
   $a = 1 + 1 ;
   echo $a ;
?>

PHP执行这段代码会经过如下4个步骤(确切的来说,应该是PHP的语言引擎Zend)

1.Scanning(Lexing) ,将PHP代码转换为语言片段(Tokens)
2.Parsing, 将Tokens转换成简单而有意义的表达式
3.Compilation, 将表达式编译成Opocdes
4.Execution, 顺次执行Opcodes,每次一条,从而实现PHP脚本的功能。
题外话:现在有的Cache比如APC,可以使得PHP缓存住Opcodes,这样,每次有请求来临的时候,就不需要重复执行前面3步,从而能大幅的提高PHP的执行速度。

更多详细解析内容请查看  chenglin博客 原文地址:http://www.chenglin.name/php/105.html

原文转载鸟哥文章 :http://www.laruence.com/2008/06/18/221.html

展开
收起
爱吃鱼的程序员 2020-06-02 17:18:05 557 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    赞+1024######php再慢也比mysql快.######这是月亮比太阳,没可比性######感觉php已经优化,臻至佳境######转载鸟哥的文章请注明出http://www.laruence.com/2008/06/18/221.html######谢谢你的说明,我已经加上了,我没找到原文链接。######不厚道,转鸟哥的,请注明,######pecl remote-info ZendOpcache
    Package details:
    ================
    Latest      7.0.3
    Installed   - no -
    Package     ZendOpcache
    License     PHP License
    Category    Caching
    Summary     The Zend OPcache provides faster PHP execution
                through opcode caching and optimization.
    Description The Zend OPcache provides faster PHP execution
                through opcode caching and
                  optimization. It improves PHP performance by
                storing precompiled script
                  bytecode in the shared memory. This eliminates
                the stages of reading code from
                  the disk and compiling it on future access. In
                addition, it applies a few
                  bytecode optimization patterns that make code
                execution faster.


    5.5的PHP在编译时可以加入--enable-opcache生成ZendOpcache,5.4编译好后可以通过pecl安装:
    pecl install ZendOpcache
    ######除了APC还有个Accelerator也是一款不错的缓存opcode的加速器。###### @雪候鸟
    2020-06-02 17:18:20
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
神龙云服务器产品及技术深度解析 立即下载
弹性创造价值:基于ECS的最佳性价比实践解析 立即下载
又快又稳:阿里云下一代虚拟交换机解析 立即下载

相关镜像