[[win32std:embeder]]
 
Table of Contents

Embeder - Make an executable Windows-binary file from a PHP script

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

Synopsis

embeder.exe action [params...]

Embeder's actions

new

Creates a new binary. For now only the console type is available.

Parameters
Ex:
C:\php\embeder>embeder new test
'.\test.exe' created

main

Put a script as the main script.

Parameters
Note

The file will be added in PHP/RUN.

Ex:
C:\php\embeder>embeder main test res/run.php
Updated 'res://.\test.exe/PHP/RUN' with 533 bytes

add

Add a file used by a script to the binary.

Parameters
Note

The file will be added in PHP/{KEY} where {KEY} is md5(file).

Ex:
C:\php\embeder>embeder add test out/console.exe
Updated 'res://.\test.exe/PHP/54a17e0796234b90551e35f245e5409e' with 20480 bytes

list

List the content of a binary file.

Parameters
Ex:
C:\php\embeder>embeder list test
Res list of '.\test.exe':
PHP
        54A17E0796234B90551E35F245E5409E
        RUN
RT_ICON
        #1
        #2
RT_GROUP_ICON
        #101

view

View a binary file resource

Parameters
Ex:
C:\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

Exemple scripts

TODO

FAQ

How to get rid of the DOS box ?

editbin /SUBSYSTEM:WINDOWS some.exe

⇒ Thanks to Reini Urban for this trick.

NEW : You can also use my PHP port of exetype.

My script doesn't run (w/o DOS box)

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', ''));

Transparent file access (How to ?)

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.

 
  win32std/embeder.txt · Last modified: 2005/02/13 12:56
 
Recent changes RSS feed Powered by PHP Driven by DokuWiki