View the PHP opcode Extension Module Web service

Source: Internet
Author: User
Tags format array execution php file php code web services access git clone

Recently it took about a week to write a php extension module Opdumer and encapsulated it as a Web service (click here to access). The main content of this module is the output of PHP code corresponding to the opcode. In fact, there have been some extension modules for viewing opcode, such as the more famous VLD. One such module is being implemented primarily because VLD does not support the Php_function API, which means that VLD can only be used in CLI forms, while Opdumer has both CLI APIs and Php_function APIs, and Also wanted to use the opportunity to write this module to learn the Zend Engine opcode compilation and execution mechanism. The individual intends to write an article specifically for the opcode compiler execution mechanism, and this article describes the use of opcode and the use of corresponding Web services.

Opdumper

installation

Opdumper's source code has been hosted on the GitHub, its address is: Https://github.com/ericzhang-cn/opdumper. You can clone the source code with the following command:

git clone https://github.com/ericzhang-cn/opdumper.git

Opdumper is a standard PHP Extension with the following installation methods:

First put the opdumper source into the PHP source code package Ext/opdumper directory, enter this directory to execute the following command:

Phpize

./configure

Make

Make install

Then add one line of configuration to php.ini:

Extension=opdumper.so

Currently, Opdumper supports php>=5.3, tests are passed under Linux and MacOS, and tests are not done under Windows.

CLI API

Opdumper supports command-line output opcode similar to VLD, simply passing opdumper.active=1 through the-D argument when executing a PHP command. For example, we have a foo.php:

<?php

$a = ' Hello ';

echo $a;

?>

Execute the following command:

php-d opdumper.active=1 foo.php

The results are as follows:

php_function API

Opdumper also supports the VLD unsupported php_function api,opdumper provides two PHP functions: od_dump_opcodes_string and Od_dump_opcodes_file. The former accepts a string as a generation, the string is a section of PHP code, the latter accepts a PHP file as a parameter, and the return value is a PHP array that has opcode results. Take Od_dump_opcodes_file as an example, we write a bar.php in the same directory foo.php:

<?php

$opcodes = Od_dump_opcodes_file ('./foo.php ');

Var_dump ($opcodes);

?>

The results of the implementation are as follows:

Array (3) {

[0]=>

Array (8) {

["Lineno"]=>

Int (2)

["OpCode"]=>

String (one) "Zend_assign"

["Op1_type"]=>

String (2) "CV"

["Op2_type"]=>

String (5) "CONST"

["Result_type"]=>

String (0) ""

["OP1"]=>

String (2) "~0"

["OP2"]=>

String (5) "Hello"

["Result"]=>

String (0) ""

}

[1]=>

Array (8) {

["Lineno"]=>

Int (3)

["OpCode"]=>

String (9) "Zend_echo"

["Op1_type"]=>

String (2) "CV"

["Op2_type"]=>

String (6) "Unused"

["Result_type"]=>

String (6) "Unused"

["OP1"]=>

String (2) "~0"

["OP2"]=>

String (6) "Unused"

["Result"]=>

String (6) "Unused"

}

[2]=>

Array (8) {

["Lineno"]=>

Int (5)

["OpCode"]=>

String (one) "Zend_return"

["Op1_type"]=>

String (5) "CONST"

["Op2_type"]=>

String (6) "Unused"

["Result_type"]=>

String (6) "Unused"

["OP1"]=>

String (1) "1"

["OP2"]=>

String (6) "Unused"

["Result"]=>

String (6) "Unused"

}

}

opdumper Web Services: Opcode dumper

Frankly, installing the PHP module is a hassle. So to make it easy for my friends to see opcode, I built an online Web service for Opdumper: Http://supercompiler.com/app/opcode_dumper.

Web page Access

Just visit this page, enter or paste into the PHP code in the edit box, you can quickly see the corresponding opcode:

You can also download the results to a local (CSV file format).

HTTP API Way Access

You can obtain the opcode of the PHP code by accessing the following APIs:

Uri:http://supercompiler.com/api/dump_opcodes

Method:post

params:php_script=[your PHP code]

The return value is in JSON format, the Success field is "true" when it succeeds, the data field stores the opcodes, the Success field is false when the failure occurs, and the MSG field holds the reason for failure.

Because of the spanning relationship, you can only use curl instead of using AJAX to invoke the API, and later add JSONP interfaces to it.

Conclusion

At present the module is relatively elementary, there are many need to improve the place. Also welcome friends who are interested to contribute code through GitHub.

Original link: http://www.codinglabs.org/html/opdumper-and-web-opcode-dumper.html



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.