Skip to main content

PHP Opcodes

First, what is an Opcode? It's a compiled form of a PHP script, similar to Java bytecode. Or, more precisely, from php.net

"When parsing PHP files, Zend Engine 2 generates a series of operation codes, commonly known as "opcodes", representing the function of the code."

<?php
  $a = "Hello ";
  $b = "World\n";
  echo $a . $b;

For a script like this, the opcodes look like that:

number of ops:  5
compiled vars:  !0 = $a, !1 = $b
line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
   2     0  >   ASSIGN                                                   !0, 'Hello+'
   3     1      ASSIGN                                                   !1, 'World%0A'
   4     2      CONCAT                                           ~2      !0, !1
         3      ECHO                                                     ~2
   5     4    > RETURN                                                   1

branch: #  0; line:     2-    5; sop:     0; eop:     4
path #1: 0,

Translate Sourcecode to op_array

Whoa. Now, how do you get the opcodes, i.e., op_array? You need a PHP extensions, like VLD (Vulcan Logic Disasembler). If you have pecl installed, you can download, build, and install it in one step by running

> sudo pecl install vld 
 
If you get an error message about a stable version, try running

> sudo pecl install vld-0.12.0

Now that you have installed it, you need to load it. In your php.ini, add the following, best if you put it close to extension=modulename.extension.

;  for op code
extension=vld.so

You find your php.ini by running
 
> php --ini
Configuration File (php.ini) Path: /usr/local/zend/etc


To generate the opcodes, all you need to do now is run the script with the following parameters (-d for ini entries)

> php -d vld.active=1 -d vld.execute=0 -f helloWorld.php

Comments

Popular posts from this blog

Uploading a file with JQuery

You can easily submit data in an html form via jQuery's $.post. But you need to do a little more to upload a file. I suggest the jQuery Form Plugin . Here is the HTML form: <html> <head> <title>Title</title> </head> <body> <form action="/test.cgi" enctype="multipart/form-data" method="post"> <input name="myFile" type="file" /> <div id="results"> </div> </form> </body> </html> This is the Javascript file myFrom.js: $(document).ready(function() { $('form').ajaxForm( { beforeSubmit: function() { $('#results').html('Submitting...'); }, success: function(data) { var $out = $('#results'); $out.html('Your results:'); $out.append('<div><pre>'+ data +'</pre></div>'); ...

Latex: Centering table larger than textwidth

Usually, you can center tables with \center. But when the table is longer than the \textwidth, it will be align with the left side margin. You can temporarily adjust the textwidth. % allows for temporary adjustment of side margins \usepackage{chngpage} \begin{table}     \begin{adjustwidth}{-.5in}{-.5in}          \begin{center}         \begin{tabular}{|c|}             \hline And here comes a very long line. And here comes a very long line. And here comes a very long line.  \\             \hline         \end{tabular}         \caption{This Table is longer than the text width. And its caption is really long, too. This Table is longer than the text width. And its caption is really long, too. This Table is lo...

Academic Job Search: Writing a good CV, research statement, and teaching statement

I won't give you boring details of how you should format your CV, there's enough resources out there that give you much better advise than I ever could, instead I will tell you what you can and should do during graduate school, to generate the content for your CV and statements. Please keep in mind that I was specifically looking for post doctoral research positions in mathematical biology . If you want to land a teaching or tenure position, some rules might be different. Job Application Timeline Academic Jobs beginning fall 2011 (June – September) Deadlines for postdocs : as early as November 2010 Asked for letters: September 2010 CV, Research Statement, Preprint/publications/thesis Draft of Research Statement August/September 2010 CV: first version in 2008, career services, periodically updated Jobs are advertised on https://www.mathjobs.org/ http://notable.math.ucdavis.edu/wiki/Mathematics_Jobs_Wiki Discussed everything with my advisor, proof-read by a...