<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>风雪之隅 &#187; ZE</title>
	<atom:link href="http://www.laruence.com/tag/ze/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com</link>
	<description>PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Wed, 08 Feb 2012 05:12:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>提升PHP性能之改变Zend引擎分发方式</title>
		<link>http://www.laruence.com/2009/10/15/1131.html</link>
		<comments>http://www.laruence.com/2009/10/15/1131.html#comments</comments>
		<pubDate>Thu, 15 Oct 2009 08:21:19 +0000</pubDate>
		<dc:creator>雪候鸟</dc:creator>
				<category><![CDATA[PHP应用]]></category>
		<category><![CDATA[PHP源码分析]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php源码分析]]></category>
		<category><![CDATA[ZE]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[效率]]></category>

		<guid isPermaLink="false">http://www.laruence.com/?p=1131</guid>
		<description><![CDATA[	从PHP5.1开始,PHP提供了用户对Zend VM执行分发方式的选择接口. 

	之前的文章中, 我也提过这方面的内容, Zend虚拟机在执行的时候, 对于编译生成的op_array中的每一条opline的opcode都会分发到相应的处理器(zend_vm_def.h定义)执行, 而按照分发的方式不同, 分发过程可以分为CALL, SWITCH, 和GOTO三种类型.

默认是CALL方式, 也就是所有的opcode处理器都定义为函数, 然后虚拟机调用. 这种方式是传统的方式, 也一般被认为是最稳定的方式.
	
SWITCH方式和GOTO方式则和其命名的意义相同, 分别通过switch和goto来分发.官方给出的描述说GOTO方式最快.

   那么如果使用GOTO方式, 效率上到底能提高多少呢? 今天我就分别使用各种方式来测试一番:]]></description>
			<content:encoded><![CDATA[<div class="copyright" >
<ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;">
<li>作者: <a href="http://www.laruence.com" >Laruence</a>(<a href="http://www.twitter.com/laruence"  target="meme"  title="Twitter" ><img src="/images/ico-twitter.png" /></a> <a href="http://t.sina.com/laruence"  target="meme"  title="新浪微博" ><img src="/images/ico-sina.png" /></a> <a href="http://fusion.google.com/add?feedurl=http://www.laruence.com/feed"  target="meme"  title="Google阅读器" ><img src="/images/ico-google.png" /></a> <a href="mailto:laruence@yahoo.com.cn"  target="meme"  title="邮件" ><img src="/images/ico-mail.png" /></a>)</li>
<li>本文地址: <a href="http://www.laruence.com/2009/10/15/1131.html"  title="Permanet Link to 提升PHP性能之改变Zend引擎分发方式" >http://www.laruence.com/2009/10/15/1131.html</a></li>
</li>
<li>转载请注明出处 </li>
</ul></div>
<p>
	从PHP5.1开始,PHP提供了用户对Zend VM执行分发方式的选择接口. </p>
<p>	之前的文章中, 我也提过这方面的内容, Zend虚拟机在执行的时候, 对于编译生成的op_array中的每一条opline的opcode都会分发到相应的处理器(zend_vm_def.h定义)执行, 而按照分发的方式不同, 分发过程可以分为CALL, SWITCH, 和GOTO三种类型.</p>
<p>	默认是CALL方式, 也就是所有的opcode处理器都定义为函数, 然后虚拟机调用. 这种方式是传统的方式, 也一般被认为是最稳定的方式.</p>
<p>	SWITCH方式和GOTO方式则和其命名的意义相同, 分别通过switch和goto来分发opcode到对应的处理逻辑(段).</p>
<p>	官方给出的描述是:</p>
<blockquote><p>
<span><br/>
CALL &#8211; Uses function handlers for opcodes<br/>
SWITCH &#8211; Uses switch() statement for opcode dispatch<br/>
GOTO &#8211; Uses goto for opcode dispatch (threaded opcodes architecture)<br/>
GOTO is usually (depends on CPU and compiler) faster than SWITCH, which<br/>
tends to be slightly faster than CALL.<br/>
CALL is default because it doesn&#8217;t take very long to compile as opposed<br/>
to the other two and in general the speed is quite close to the others.<br/>
</span>
</p></blockquote>
<p>   那么如果使用GOTO方式, 效率上到底能提高多少呢?</p>
<p>   今天我就分别使用各种方式来测试一番, 测试脚本<a href="http://www.laruence.com/2009/10/15/1131.html#bench" >bench.php</a>.</p>
<p>   第一点被证明的就是, 官方说的GOTO方式编译耗时显著高于其他俩种方式, 我一开始在虚拟机上编译, 每次都Hangup(囧), 最后只好换了个强劲点的物理机, 大约3分钟后, 编译成功..</p>
<p>   测试环境:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
PHP 5.3.0   Linux
AMD Opteron(tm) Processor 270(2G) X 4  6G Memory
</pre>
<p>   编译参数:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
./configure --with-zend-vm=CALL/GOTO/SWITCH
</pre>
<p>  测试结果如下(都是三次取中值):</p>
<p>CALL方式:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
laruence@dev01.tc$ sapi/cli/php bench.php
simple             0.358
simplecall         0.418
simpleucall        0.405
simpleudcall       0.424
mandel             1.011
mandel2            1.238
ackermann(7)       0.375
ary(50000)         0.083
ary2(50000)        0.075
ary3(2000)         0.561
fibo(30)           1.156
hash1(50000)       0.114
hash2(500)         0.091
heapsort(20000)    0.270
matrix(20)         0.276
nestedloop(12)     0.599
sieve(30)          0.350
strcat(200000)     0.039
------------------------
Total              7.844
</pre>
<p>SWITCH方式:</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
laruence@dev01.tc$ sapi/cli/php bench.php
simple             0.393
simplecall         0.414
simpleucall        0.424
simpleudcall       0.445
mandel             1.007
mandel2            1.254
ackermann(7)       0.392
ary(50000)         0.084
ary2(50000)        0.073
ary3(2000)         0.593
fibo(30)           1.185
hash1(50000)       0.120
hash2(500)         0.092
heapsort(20000)    0.285
matrix(20)         0.295
nestedloop(12)     0.678
sieve(30)          0.359
strcat(200000)     0.042
------------------------
Total              8.138
</pre>
<p>GOTO方式 :</p>
<pre name="code"  class="sh_shell"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
laruence@dev01.tc$ sapi/cli/php bench.php
simple             0.306
simplecall         0.373
simpleucall        0.369
simpleudcall       0.385
mandel             0.879
mandel2            1.132
ackermann(7)       0.356
ary(50000)         0.081
ary2(50000)        0.073
ary3(2000)         0.525
fibo(30)           1.043
hash1(50000)       0.111
hash2(500)         0.088
heapsort(20000)    0.247
matrix(20)         0.247
nestedloop(12)     0.519
sieve(30)          0.331
strcat(200000)     0.037
------------------------
Total              7.103
</pre>
<p>可见, <b>GOTO方式最快, SWITCH方式最慢.</b>和官方的描述稍有不符.</p>
<p>GOTO方式比其默认的CALL方式, 性能提升还是比较明显的. </p>
<p>所以, 如果你希望让PHP发挥到机制, 改变Zend VM的分发方式, 也可以做为一个考虑因素.
</p>
<p>
附:</p>
<p>使用GOTO方式的configure选项:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
--with-zend-vm=GOTO
</pre>
<p>也可以在Zend目录下使用:</p>
<pre name="code"  class="sh_bash"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
php zend_vm_gen.php --with-vm-kind=[CALL|GOTO|SWITH]
</pre>
<p><a name="bench" > </a>测试脚本bench.php</p>
<pre name="code"  class="sh_php"  linenum="off"   style="background: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:Monacobackground: #333; color: #d9d9d9; border-left: 15px solid #c9c9c9; padding: 9px; font-size: 1em; overflow-x: auto;font-family:MonacoConsolasConsolasCourierCouriermonospace;monospace;">
&lt;?php
/**
 * PHP Perf Bench Test Script
 */
function simple() {
  $a = 0;
  for ($i = 0; $i &lt; 1000000; $i++)
    $a++;

  $thisisanotherlongname = 0;
  for ($thisisalongname = 0; $thisisalongname &lt; 1000000; $thisisalongname++)
    $thisisanotherlongname++;
}

/****/

function simplecall() {
  for ($i = 0; $i &lt; 1000000; $i++)
    strlen(&quot;hallo&quot;);
}

/****/

function hallo($a) {
}

function simpleucall() {
  for ($i = 0; $i &lt; 1000000; $i++)
    hallo(&quot;hallo&quot;);
}

/****/

function simpleudcall() {
  for ($i = 0; $i &lt; 1000000; $i++)
    hallo2(&quot;hallo&quot;);
}

function hallo2($a) {
}

/****/

function mandel() {
  $w1=50;
  $h1=150;
  $recen=-.45;
  $imcen=0.0;
  $r=0.7;
  $s=0;  $rec=0;  $imc=0;  $re=0;  $im=0;  $re2=0;  $im2=0;
  $x=0;  $y=0;  $w2=0;  $h2=0;  $color=0;
  $s=2*$r/$w1;
  $w2=40;
  $h2=12;
  for ($y=0 ; $y&lt;=$w1; $y=$y+1) {
    $imc=$s*($y-$h2)+$imcen;
    for ($x=0 ; $x&lt;=$h1; $x=$x+1) {
      $rec=$s*($x-$w2)+$recen;
      $re=$rec;
      $im=$imc;
      $color=1000;
      $re2=$re*$re;
      $im2=$im*$im;
      while( ((($re2+$im2)&lt;1000000) &amp;&amp; $color&gt;0)) {
        $im=$re*$im*2+$imc;
        $re=$re2-$im2+$rec;
        $re2=$re*$re;
        $im2=$im*$im;
        $color=$color-1;
      }
      if ( $color==0 ) {
        print &quot;_&quot;;
      } else {
        print &quot;#&quot;;
      }
    }
    print &quot;&lt;br&gt;&quot;;
    flush();
  }
}

/****/

function mandel2() {
  $b = &quot; .:,;!/&gt;)|&amp;IH%*#&quot;;
  //float r, i, z, Z, t, c, C;
  for ($y=30; printf(&quot;\n&quot;), $C = $y*0.1 - 1.5, $y--;){
    for ($x=0; $c = $x*0.04 - 2, $z=0, $Z=0, $x++ &lt; 75;){
      for ($r=$c, $i=$C, $k=0; $t = $z*$z - $Z*$Z + $r, $Z = 2*$z*$Z + $i, $z=$t, $k&lt;5000; $k++)
        if ($z*$z + $Z*$Z &gt; 500000) break;
      echo $b[$k%16];
    }
  }
}

/****/

function Ack($m, $n){
  if($m == 0) return $n+1;
  if($n == 0) return Ack($m-1, 1);
  return Ack($m - 1, Ack($m, ($n - 1)));
}

function ackermann($n) {
  $r = Ack(3,$n);
  print &quot;Ack(3,$n): $r\n&quot;;
}

/****/

function ary($n) {
  for ($i=0; $i&lt;$n; $i++) {
    $X[$i] = $i;
  }
  for ($i=$n-1; $i&gt;=0; $i--) {
    $Y[$i] = $X[$i];
  }
  $last = $n-1;
  print &quot;$Y[$last]\n&quot;;
}

/****/

function ary2($n) {
  for ($i=0; $i&lt;$n;) {
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;

    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
    $X[$i] = $i; ++$i;
  }
  for ($i=$n-1; $i&gt;=0;) {
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;

    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
    $Y[$i] = $X[$i]; --$i;
  }
  $last = $n-1;
  print &quot;$Y[$last]\n&quot;;
}

/****/

function ary3($n) {
  for ($i=0; $i&lt;$n; $i++) {
    $X[$i] = $i + 1;
    $Y[$i] = 0;
  }
  for ($k=0; $k&lt;1000; $k++) {
    for ($i=$n-1; $i&gt;=0; $i--) {
      $Y[$i] += $X[$i];
    }
  }
  $last = $n-1;
  print &quot;$Y[0] $Y[$last]\n&quot;;
}

/****/

function fibo_r($n){
    return(($n &lt; 2) ? 1 : fibo_r($n - 2) + fibo_r($n - 1));
}

function fibo($n) {
  $r = fibo_r($n);
  print &quot;$r\n&quot;;
}

/****/

function hash1($n) {
  for ($i = 1; $i &lt;= $n; $i++) {
    $X[dechex($i)] = $i;
  }
  $c = 0;
  for ($i = $n; $i &gt; 0; $i--) {
    if ($X[dechex($i)]) { $c++; }
  }
  print &quot;$c\n&quot;;
}

/****/

function hash2($n) {
  for ($i = 0; $i &lt; $n; $i++) {
    $hash1[&quot;foo_$i&quot;] = $i;
    $hash2[&quot;foo_$i&quot;] = 0;
  }
  for ($i = $n; $i &gt; 0; $i--) {
    foreach($hash1 as $key =&gt; $value) $hash2[$key] += $value;
  }
  $first = &quot;foo_0&quot;;
  $last  = &quot;foo_&quot;.($n-1);
  print &quot;$hash1[$first] $hash1[$last] $hash2[$first] $hash2[$last]\n&quot;;
}

/****/

function gen_random ($n) {
    global $LAST;
    return( ($n * ($LAST = ($LAST * IA + IC) % IM)) / IM );
}

function heapsort_r($n, &amp;$ra) {
    $l = ($n &gt;&gt; 1) + 1;
    $ir = $n;

    while (1) {
        if ($l &gt; 1) {
            $rra = $ra[--$l];
        } else {
            $rra = $ra[$ir];
            $ra[$ir] = $ra[1];
            if (--$ir == 1) {
                $ra[1] = $rra;
                return;
            }
        }
        $i = $l;
        $j = $l &lt;&lt; 1;
        while ($j &lt;= $ir) {
            if (($j &lt; $ir) &amp;&amp; ($ra[$j] &lt; $ra[$j+1])) {
                $j++;
            }
            if ($rra &lt; $ra[$j]) {
                $ra[$i] = $ra[$j];
                $j += ($i = $j);
            } else {
                $j = $ir + 1;
            }
        }
        $ra[$i] = $rra;
    }
}

function heapsort($N) {
  global $LAST;

  define(&quot;IM&quot;, 139968);
  define(&quot;IA&quot;, 3877);
  define(&quot;IC&quot;, 29573);

  $LAST = 42;
  for ($i=1; $i&lt;=$N; $i++) {
    $ary[$i] = gen_random(1);
  }
  heapsort_r($N, $ary);
  printf(&quot;%.10f\n&quot;, $ary[$N]);
}

/****/

function mkmatrix ($rows, $cols) {
    $count = 1;
    $mx = array();
    for ($i=0; $i&lt;$rows; $i++) {
        for ($j=0; $j&lt;$cols; $j++) {
            $mx[$i][$j] = $count++;
        }
    }
    return($mx);
}

function mmult ($rows, $cols, $m1, $m2) {
    $m3 = array();
    for ($i=0; $i&lt;$rows; $i++) {
        for ($j=0; $j&lt;$cols; $j++) {
            $x = 0;
            for ($k=0; $k&lt;$cols; $k++) {
                $x += $m1[$i][$k] * $m2[$k][$j];
            }
            $m3[$i][$j] = $x;
        }
    }
    return($m3);
}

function matrix($n) {
  $SIZE = 30;
  $m1 = mkmatrix($SIZE, $SIZE);
  $m2 = mkmatrix($SIZE, $SIZE);
  while ($n--) {
    $mm = mmult($SIZE, $SIZE, $m1, $m2);
  }
  print &quot;{$mm[0][0]} {$mm[2][3]} {$mm[3][2]} {$mm[4][4]}\n&quot;;
}

/****/

function nestedloop($n) {
  $x = 0;
  for ($a=0; $a&lt;$n; $a++)
    for ($b=0; $b&lt;$n; $b++)
      for ($c=0; $c&lt;$n; $c++)
        for ($d=0; $d&lt;$n; $d++)
          for ($e=0; $e&lt;$n; $e++)
            for ($f=0; $f&lt;$n; $f++)
             $x++;
  print &quot;$x\n&quot;;
}

/****/

function sieve($n) {
  $count = 0;
  while ($n-- &gt; 0) {
    $count = 0;
    $flags = range (0,8192);
    for ($i=2; $i&lt;8193; $i++) {
      if ($flags[$i] &gt; 0) {
        for ($k=$i+$i; $k &lt;= 8192; $k+=$i) {
          $flags[$k] = 0;
        }
        $count++;
      }
    }
  }
  print &quot;Count: $count\n&quot;;
}

/****/

function strcat($n) {
  $str = &quot;&quot;;
  while ($n-- &gt; 0) {
    $str .= &quot;hello\n&quot;;
  }
  $len = strlen($str);
  print &quot;$len\n&quot;;
}

/*****/

function getmicrotime()
{
  $t = gettimeofday();
  return ($t['sec'] + $t['usec'] / 1000000);
}

function start_test()
{
        ob_start();
  return getmicrotime();
}

function end_test($start, $name)
{
  global $total;
  $end = getmicrotime();
  ob_end_clean();
  $total += $end-$start;
  $num = number_format($end-$start,3);
  $pad = str_repeat(&quot; &quot;, 24-strlen($name)-strlen($num));

  echo $name.$pad.$num.&quot;\n&quot;;
        ob_start();
  return getmicrotime();
}

function total()
{
  global $total;
  $pad = str_repeat(&quot;-&quot;, 24);
  echo $pad.&quot;\n&quot;;
  $num = number_format($total,3);
  $pad = str_repeat(&quot; &quot;, 24-strlen(&quot;Total&quot;)-strlen($num));
  echo &quot;Total&quot;.$pad.$num.&quot;\n&quot;;
}

$t0 = $t = start_test();
simple();
$t = end_test($t, &quot;simple&quot;);
simplecall();
$t = end_test($t, &quot;simplecall&quot;);
simpleucall();
$t = end_test($t, &quot;simpleucall&quot;);
simpleudcall();
$t = end_test($t, &quot;simpleudcall&quot;);
mandel();
$t = end_test($t, &quot;mandel&quot;);
mandel2();
$t = end_test($t, &quot;mandel2&quot;);
ackermann(7);
$t = end_test($t, &quot;ackermann(7)&quot;);
ary(50000);
$t = end_test($t, &quot;ary(50000)&quot;);
ary2(50000);
$t = end_test($t, &quot;ary2(50000)&quot;);
ary3(2000);
$t = end_test($t, &quot;ary3(2000)&quot;);
fibo(30);
$t = end_test($t, &quot;fibo(30)&quot;);
hash1(50000);
$t = end_test($t, &quot;hash1(50000)&quot;);
hash2(500);
$t = end_test($t, &quot;hash2(500)&quot;);
heapsort(20000);
$t = end_test($t, &quot;heapsort(20000)&quot;);
matrix(20);
$t = end_test($t, &quot;matrix(20)&quot;);
nestedloop(12);
$t = end_test($t, &quot;nestedloop(12)&quot;);
sieve(30);
$t = end_test($t, &quot;sieve(30)&quot;);
strcat(200000);
$t = end_test($t, &quot;strcat(200000)&quot;);
total($t0, &quot;Total&quot;);
?&gt;
</pre>
</p>
<p><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_shell.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_bash.js" ></script><script type="text/javascript"  src="http://www.laruence.com/wp-content/plugins/shjs-syntax-hiliter/shjs/lang/sh_php.js" ></script></p>
<hr/><h2>Comments</h2><ul  style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/15</a>, <a href="http://www.codytan.com"  rel="external nofollow"  class="url" >cody</a> writes: 好文，不过有些疑问
1.“对于每个Opcode都会分发执行”，这里的“个"指的是？是一条opcode语句还是一个php文件中所有的opcode语句？
2.有个问题，php的错误检查阶段是哪个？不是语法检查。如include一个不存在的问题，php会报错，这个报错是在opcode-&gt;compile-&gt;执行中的哪个环节报错的？是compile环节还是执行环节呢？
3.其实问题二是基于对php运行机制还不太清楚，我测试过一个文件 include 20个php文件和直接写成一个php文件性能上的差异很大（20文件并不执行），想知道是在哪个环境造成了这种差异。

如果能回答我，感激不尽！ :)</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/15</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @cody 应该是对于每条opline中的opcode. 都会通过分发对应到相应的处理器执行(zend_vm_def.h定义).
include也是一条opcode,ZEND_INCLUDE_OR_EVAL, 相应的出错检查也就是在它的处理器中.</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/15</a>, <a href="http://www.codytan.com"  rel="external nofollow"  class="url" >cody</a> writes: 补充一下，”opcode-&gt;compile-&gt;执行“ 我这里的compile指的其实是由opcode到c 这个过程。</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/15</a>, cody writes: thanks</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/17</a>, fybird writes: 请问你是用那个ide编程，平常。</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/17</a>, <a href="http://www.laruence.com"  rel="external nofollow"  class="url" >雪候鸟</a> writes: @fybird vim</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/24</a>, <a href="http://www.05sky.cn"  rel="external nofollow"  class="url" >CrossYou</a> writes: 我也使用了你同样的主题，呵呵

你的文章写的很深，我才刚刚接触php，学习中，楼主加油。</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2009/10/26</a>, zhangyufeng writes: http://twiki.laruence.com/ 打不开啦……</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2010/03/21</a>, <a href="http://t.sina.com.cn/liruqi"  rel="external nofollow"  class="url" >liruqi</a> writes: 建议做bench的时候，把计算代码和输出代码分离测试。因为io部分所费的时间不好预测。</li><li><a href="http://www.laruence.com/2009/10/15/1131.html" >2011/03/20</a>, <a href="http://www.w3hacker.com/?p=202"  rel="external nofollow"  class="url" >提升PHP性能之改变Zend引擎分发方式 | 万维网黑客联盟</a> writes: [...] 本文地址: http://www.laruence.com/2009/10/15/1131.html [...]</li></ul><hr/><small  style="font-size:85%;font-size:85%;">Copyright &copy; 2010 <a href="http://www.laruence.com"  target="_blank" >风雪之隅</a> 版权所有, 转载务必注明. 该Feed只供个人使用, 禁止未注明的转载或商业应用. 非法应用的, 一切法律后果自负. 如有问题, 可发E-mail至my at laruence.com.(Digital Fingerprint: 73540ba0a1738d7d07d4b6038d5615e2)</small><h2 class="related_post_title" >Related Posts:</h2><ul class="related_post"   style="padding-left:1em;font-size:85%;padding-left:1em;font-size:85%;"><li><a href="http://www.laruence.com/2011/12/30/2435.html"  title="PHP数组的Hash冲突实例" >PHP数组的Hash冲突实例</a></li><li><a href="http://www.laruence.com/2011/03/04/1894.html"  title="深入理解PHP内存管理之谁动了我的内存" >深入理解PHP内存管理之谁动了我的内存</a></li><li><a href="http://www.laruence.com/2010/05/26/1541.html"  title="PHP类型转换相关的一个Bug" >PHP类型转换相关的一个Bug</a></li><li><a href="http://www.laruence.com/2010/05/20/1495.html"  title="Nginx + PHP CGI的一个可能的安全漏洞" >Nginx + PHP CGI的一个可能的安全漏洞</a></li><li><a href="http://www.laruence.com/2010/05/18/1482.html"  title="深入理解PHP原理之对象(一)" >深入理解PHP原理之对象(一)</a></li><li><a href="http://www.laruence.com/2009/12/26/1198.html"  title="深入理解PHP原理之变量生命期(一)" >深入理解PHP原理之变量生命期(一)</a></li><li><a href="http://www.laruence.com/2009/11/27/1164.html"  title="memory_limit的一个bug" >memory_limit的一个bug</a></li><li><a href="http://www.laruence.com/2009/09/26/1103.html"  title="PHP文件上传源码分析(RFC1867)" >PHP文件上传源码分析(RFC1867)</a></li><li><a href="http://www.laruence.com/2009/07/27/1020.html"  title="深入理解PHP原理之错误抑制与内嵌HTML" >深入理解PHP原理之错误抑制与内嵌HTML</a></li><li><a href="http://www.laruence.com/2008/08/24/377.html"  title="PHP源码分析之Global关键字" >PHP源码分析之Global关键字</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.laruence.com/2009/10/15/1131.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

