<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Luca Abbati</title>
    <description>The latest articles on DEV Community by Luca Abbati (@labbati).</description>
    <link>https://dev.to/labbati</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F338322%2Fe7d95252-2b0a-4b05-918d-1dc6089f2ad2.jpeg</url>
      <title>DEV Community: Luca Abbati</title>
      <link>https://dev.to/labbati</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/labbati"/>
    <language>en</language>
    <item>
      <title>Dump PHP 7.1+ opcodes</title>
      <dc:creator>Luca Abbati</dc:creator>
      <pubDate>Tue, 23 Mar 2021 13:39:35 +0000</pubDate>
      <link>https://dev.to/labbati/how-to-dump-php-opcodes-4c5</link>
      <guid>https://dev.to/labbati/how-to-dump-php-opcodes-4c5</guid>
      <description>&lt;p&gt;If you are working on PHP internals and you need to know which opcodes are generated for a given script, here is the command you can use to dump them.&lt;/p&gt;

&lt;p&gt;Assume the file &lt;code&gt;index.php&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

echo "hello";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can dump opcodes running the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ php -n -d zend_extension=opcache.so -d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.opt_debug_level=0x10000 index.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-n&lt;/code&gt;: [optional] disable all extensions, you will enable only the ones you are interested in;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d zend_extension=opcache.so&lt;/code&gt;: load the &lt;code&gt;Zend OPcache&lt;/code&gt; extension;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d opcache.enable=1&lt;/code&gt;: enable the &lt;code&gt;Zend OPcache&lt;/code&gt; extension;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d opcache.enable_cli=1&lt;/code&gt;: enable the &lt;code&gt;Zend OPcache&lt;/code&gt; extension for the CLI SAPI (required for the command line);&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-d opcache.opt_debug_level=0x10000&lt;/code&gt;: disable opcodes optimization - &lt;a href="https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.opt_debug_level"&gt;docs&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The output of this command is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$_main: ; (lines=2, args=0, vars=0, tmps=0)
    ; (before optimizer)
    ; /var/www/html/public/index.php:1-10
L0:     ECHO string("hello")
L1:     RETURN int(1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Originally, inspired by the excellent Nikita Popov's &lt;a href="https://www.npopov.com/2017/04/14/PHP-7-Virtual-machine.html"&gt;post&lt;/a&gt; about the PHP 7 virtual machine.&lt;/p&gt;

</description>
      <category>php</category>
      <category>zendengine</category>
    </item>
  </channel>
</rss>
