====== 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 [[index|win32std]]. **Pre-requisites :** For the binary version you need the [[php>downloads.php|PHP5 binaries]]. **Note :** You can do the same by including the resource before the compilation in any Visual Studio Project it's explained [[howto:embeding_a_php_source_into_a_windows_executable_file|here]]. **License :** [[http://www.php.net/license/3_0.txt|PHP License]] **Download :** [[:downloads#Embeder|Download page]] **Tutorial :** [[win32std:embeder_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 == * ''name'' : Name of the binary (without the ''.exe'') == Ex: == C:\php\embeder>embeder new test '.\test.exe' created === main === Put a script as the main script. == Parameters == * ''name'' : Name of the binary (without the ''.exe'') * ''file'' : Filename of the file to add. == 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 == * ''name'' : Name of the binary (without the ''.exe'') * ''file'' : Filename of the file to add. == 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 == * ''name'' : Name of the binary (without the ''.exe'') == 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 == * ''name'' : binary name (without the ''.exe'') * ''section'' : resource's section (ie: "PHP") * ''value'' : resource's key == Ex: == C:\php\embeder>embeder view test PHP RUN -Displaying 'res://.\test.exe/PHP/RUN' // http://wildphp.free.fr/wiki/doku?id=win32std:embeder //======================================================================== ?> - Powered by PHP version Empty base binary. -End ===== Exemple scripts ===== * Find exemple scripts in the [[:downloads#embeder|distribution]] under ''test_project/''. * Also check the [[win32std:embeder_tutorial|Embeder's tutorial]] ===== TODO ===== * Allow an intermediate state ([[http://www.coggeshall.org/oss/blenc//index.php/5/|blenc-oding]] ?) * Due to a win32std limitation the function file_exists doesn't work properly with ''_f'' * Make the win32std check in main.cpp * Define EMBEDED_DATE and EMBEDED_VERSION containing the creation date & Software version (available for r/w by embeder's date/version actions) * Add multiples ''exe'' types. * Define EMBEDED_{TYPE} to reflect the exe type ===== FAQ ===== ==== How to get rid of the DOS box ? ==== * Using MSVC tools : editbin /SUBSYSTEM:WINDOWS some.exe * You can also use some simple small //Perl// script to change the byte in the exe header (available [[http://jenda.krynicky.cz/perl/GUIscripts.html|here]]). => Thanks to [[http://xarch.tu-graz.ac.at/home/rurban/|Reini Urban]] for this trick. **NEW : ** You can also use my [[http://wildphp.free.fr/dl.php?file=exetype-bin-20050118.zip|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 - [[http://cvs.php.net/co.php/php-src/sapi/embed/php_embed.c?r=1.9#55|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 [[win32std:Embeder#Exemple scripts|Exemple scripts]] for an exemple.