What is it ? Embeder is a little command line utility that allow the creation of Windows binary that runs PHP scripts.
How does it work ? It make use of the embed PHP SAPI and win32std.
Pre-requisites : For the binary version you need the PHP5 binaries.
Note : You can do the same by including the resource before the compilation in any Visual Studio Project it’s explained here.
License : PHP License
Download : Download page
Tutorial : Embeder's tutorial
embeder.exe action [params...]
Creates a new binary.
For now only the console type is available.
name : Name of the binary (without the .exe)C:\php\embeder>embeder new test '.\test.exe' created
Put a script as the main script.
name : Name of the binary (without the .exe)file : Filename of the file to add.
The file will be added in PHP/RUN.
C:\php\embeder>embeder main test res/run.php Updated 'res://.\test.exe/PHP/RUN' with 533 bytes
Add a file used by a script to the binary.
name : Name of the binary (without the .exe)file : Filename of the file to add.
The file will be added in PHP/{KEY} where {KEY} is md5(file).
C:\php\embeder>embeder add test out/console.exe Updated 'res://.\test.exe/PHP/54a17e0796234b90551e35f245e5409e' with 20480 bytes
List the content of a binary file.
name : Name of the binary (without the .exe)
C:\php\embeder>embeder list test
Res list of '.\test.exe':
PHP
54A17E0796234B90551E35F245E5409E
RUN
RT_ICON
#1
#2
RT_GROUP_ICON
#101
View a binary file resource
name : binary name (without the .exe)section : resource’s section (ie: “PHP”)value : resource’s keyC:\php\embeder>embeder view test PHP RUN -Displaying 'res://.\test.exe/PHP/RUN' <? //======================================================================== // Embeder - Make an executable Windows-binary file from a PHP script // // License : PHP License (http://www.php.net/license/3_0.txt) // Author : Eric Colinet <e dot colinet at laposte dot net> // http://wildphp.free.fr/wiki/doku?id=win32std:embeder //======================================================================== ?> <?=basename($argv[0])?> - Powered by PHP version <?=phpversion()."\n"?> Empty base binary. -End
test_project/.
_fexe types.
editbin /SUBSYSTEM:WINDOWS some.exe
⇒ Thanks to Reini Urban for this trick.
NEW : You can also use my PHP port of exetype.
There is a drawback of using the standard embed SAPI in the WINDOWS SUBSYSTEM : If you output something embed will silently consider that the connection is aborded (write to stdout fail - Ref).
One of the solutions is to buffer the output using ob_start.
On top of the main script :
function _write_null($txt) {} ob_start('_write_null');
Or shorter:
ob_start(create_function('$txt', ''));
To access files transparently you can use a filename wrapper:
function _f($file, $force=false) { return $force||defined('EMBEDED')?'res:///PHP/'.md5($file):$file; }
Note: The constant EMBEDED is defined by Embeder.
And then, for each reference to a file, enclose the filename by your wrapper function:
include _f('include.inc');
Look at Exemple scripts for an exemple.