How can I write PHP opcode, save it in a file and make the Zend Engine execute it? Any method or hack is welcome, as long as it does the trick.
Writing PHP opcode and have it executed. How to do?
Asked Answered
<smile> at "no well-intentioned answers that are not precisely addressing [the] question". Are miserable or angry answers that don't address the question acceptable? –
Prefect
@Prefect ... look at Mo.sch's answer ... PHP-questions always attract such answers ... and did you -1 one me? oh man ... –
Borneol
No, no -1 from me; I always try to state why I downvote :) –
Prefect
Why downvote? It's a perfectly valid (and interesting) question. –
Gonzalez
@Gonzalez - yes, it's a good question. The downvotes may have been for the way the question was originally asked, but it has now been nicely improved. –
Prefect
Would be nice with an update to this question. Some years have passed. :) –
Brendon
There's a couple of user-space methods (from plugins) that can deal with Opcodes.
- http://uk.php.net/apc_bin_load (and http://uk.php.net/apc_bin_dump)
- http://uk.php.net/bcompiler_read / http://uk.php.net/bcompiler_write_file
Neither produces plain text however because the opcodes are not designed to be a user-writable language (unlike Parrot).
that means I could overwrite a cached file with apc_bin_load, I guess ... so next question would be how the nice looking opcode statements relate to the actually used binary representation. do you know something about that? references or so? –
Borneol
https://mcmap.net/q/262531/-how-to-get-opcodes-of-php has some information, mostly referring to "Vulcan Logic Dumper" - pecl.php.net/package/vld –
Katt
There is an extension called ulopcodes that allows you to emit your own opcodes via a function that it exposes to PHP code.
For example:
ulopcodes_emit(ZEND_ECHO, "Hello world!");
Will create that line in the current oparray which will be executed by the VM.
This extension is purely educational and not intended to be used in production code.
(Disclaimer: I am the creator of ulopcodes)
Yes, you can use vld for instance to output the generated opcodes. –
Enclitic
© 2022 - 2024 — McMap. All rights reserved.