WinBinder - The native Windows binding for PHP
WinBinder is a PHP extension written in C, that allows you to build native client-side applications for the Windows Platform in pure PHP.
You will need PHP 5.3/5.4 plus the WinBinder matching your PHP version.
- use one of the *.dlls in the binaries subfolder
- compile it yourself
- get a version of Visual Studio (this how to refers to Visual Studio 2008 Professional)
- get the PHP binaries you want to use with WinBinder, e.g. VC9 x86 Thread Safe 5.4
- get the PHP source matching the binary version from above, e.g. VC9 x86 Thread Safe 5.4
- get the WinBinder source code
- create the project: either create a new Visual C++ project, or import from existing source - make your new project a "Win32 Project", call it php_winbinder, or pick any name you like - select "DLL" as application type
-
change default C++ options:
-
right click your project and select "Properties"
-
under "Configuration Properties" select "General"
- set "Character Set" to "Use Multi-Byte Character Set"
-
under "Configuration Properties" select "C/C++", and there select "General"
- set "Debug Information Format" to "Program Database (/Zi)""
- set "Detect 64-bit Portability Issues" to "No"
-
under "Configuration Properties" select "C/C++", and there select "Code Generation"
- set "Enable String Pooling" to "Yes (/GF)"
- set "Enable Minimal Rebuild" to "No"
- set "Basic Runtime Checks" to "Default"
- set "Runtime Library" to "Multi-threaded Debug (/MTd)"
-
-
set the include path:
- again, under "Configuration Properties" select "C/C++", and there select "General"
- set the include path as following (adapting to your case)
- C:\path\to\php\source\main
- C:\path\to\php\source\Zend
- C:\path\to\php\source\TSRM
- C:\path\to\php\source\regex
- C:\path\to\php\source
- C:\path\to\php\source\ext\standard
- set the include path as following (adapting to your case)
- again, under "Configuration Properties" select "C/C++", and there select "General"
-
set the Preprocessor Definitions:
- again, under "Configuration Properties" select "C/C++", and there select "Preprocessor"
- add the following definitions
- ZEND_DEBUG=0
- ZTS=1
- ZEND_WIN32
- PHP_WIN32
- add the following definitions
- again, under "Configuration Properties" select "C/C++", and there select "Preprocessor"
-
set the Linker Options:
-
under "Configuration Properties" select "Linker", and there select "General"
- set "Additional Library Directories" to C:\path\to\php\binary\dev
-
under "Configuration Properties" select "Linker", and there select "Input"
- add "php5.lib" (for non-thred-safe version) or "php5ts.lib" (for thread-safe version) to "Additional Dependecies"
-
-
edit stdafx.h:
- replace the contents of stdafx.h with the following, if it does not match already:
#pragma once
/* PHP Extension headers /
/ include zend win32 config first /
#include "zend_config.w32.h"
/ include standard header */
#include "php.h"
- replace the contents of stdafx.h with the following, if it does not match already:
You may now try to compile the extension. When successful, it is located in the folder "Debug" of your Visual Studio project.
-
However, it's more likely, that you run into some errors like:
-
fatal error C1083: "../main/config.w32.h": No such file or directory
- open a Visual Studio command prompt and change into you PHP source directory
- run the command "buildconf.bat"
- run the command "cscript /nologo configure.js"
-
great, now I get "ERROR: bison is required"
- either get bison, or open "configure.js" and comment out the following line ... ERROR('bison is required') ... and re-run "cscript /nologo configure.js"
-
fatal error C1853: something about pre-compiled headers
- again, under "Configuration Properties" select "C/C++", and there select "Precompiled Headers"
- set "Use Precompiled Headers" to "Do not use precompiled headers"
- again, under "Configuration Properties" select "C/C++", and there select "Precompiled Headers"
-
error C2466: cannot allocate an array of constant size 0
- go to "C:\path\to\php\source\main" and open "config.w32.h"
- comment out the following lines
#ifndef _WIN64
#define _USE_32BIT_TIME_T 1
#endif
#define HAVE_STDLIB_H 1
-
error LNK2005: **** already defined in %%%%%
- delete files automatically generated by Visual Studio from the project, i.e. stdafx.cpp and dllmain.cpp (maybe more?)
-
fatal error LNK1000: Internal error during IncrBuildImage
- update your Visual Studio, LNK1000 may happen due to a bug
- under "Configuration Properties" select "Linker", and there select "General"
- set "activate incrementel linking" to "No"
-
Be sure to check out the docs folder. There are also examples in the phpcode folder. Futhermore, you can go to www.winbinder.org, there is also a forum.