PHP WinBinder: Introduction
WinBinder Plugin Introduction
PHP’s command line interface “CLI” is extremely powerful, however using a command window for user interfacing is restrictive. An ideal solution would be to use a Windows interface.
WinBinder provides a neat solution. It remains actively supported by the open source community. Of importance, the WinBinder extension php_winbinder.dll is being compiled for new versions of PHP (currently 5.3.1), hence WinBinder is alive and kicking.
This plugin uses WinBinder to provide a PHP CLI Windows interface. It intentionally does not include a compiler. If you wish to produce standalone code, check out PHC-Win.
Windows applications are generally coded in “C”, so before they can be executed, they must be compiled. In contrast this self-contained plugin uses WinBinder, allowing an application to be coded in PHP. This has the advantage of providing a common language for web-design, control architecture and user interface. It eliminates the need to learn a new language.
The WinBinder plugin is self-contained allowing it to be run independently of Uniform Server. However it is designed to fit neatly into Uniform Server’s control architecture thus providing an alternative control interface. If space is at a premium the plugin can be overlayed onto Uniform Server allowing it to use the existing PHP core (VC6).
During development, windows scripts are run using a batch file. This batch file can be converted to an .exe using a small utility program included with the plugin.
This tutorial explains how to use the plugin and introduces some basics of windows programming using WinBinder.
An emphasis is on scripting, so I have avoided the complexity of compiling a windows application. Even with this restriction you can deploy a single file windows application; all necessary files are compressed using the included utility.
The tutorial format is based around working examples; first basic principles are explained, followed by a working script you can run.
Basic IO introduces two windows components Labels and Push button.
Label text can be dynamically changed, providing user feedback.
The example shows how to change text using a push button and introduces the Handler Function (callback function).
Text input allows a user to enter either a text string or numeric data.
Included is the "draw rectangle" function. This can be used for user feedback.
Introduces a control's style parameter.
Tab Control 1
Tab Control allows a designer to split a single page application that has become too visually crowded into smaller logical pages.
Tab Control 2
Tab Control 2 Looks at coding style Handles and ID’s concludes with a working template.
Tab Control 3
Tab Control 3 Covers adding cosmetics (static controls) a logo (icon) and some additional functionality to produce a specific application template.
Project 1 This page looks at creating a separate Windows application independent of Uniform Server. Applications produced using this method, are not compiled hence are not standalone executables. They require several support files.
That said, they are easy to program using PHP and Winbinder
Project 2 This page looks at Bat_To_Exe Converter from Fatih Kodak combined with WinBinder produces a windows application coded in PHP without the need for compiling.
An entire windows project can be distributed and run as a single (exe) file.
Alternative control 1
Uniform server 4-Mona series introduced UniController a simple Windows program written in C to control both Apache and MySQL servers.
This page looks at converting this application into a WinBinder script.
Alternative control 2
Alternative control 2 This page is a continuation of the alternative control.
It covers starting and stopping Apache and MySQL servers from a windows application. It introduces the timer control and concludes with a fully functional server.
Alternative control 3
Alternative control 3 Adding functionality to buttons Logs, Edit and Test requires access to several files that in turn require additional buttons. At a later date you may require that extra button! Solution is to replace the three buttons with a drop down menuthis requires minimal changes and offers expandability.
Alternative control 4
Alternative control 4 WinBinder has a few limitations most of which can be worked around. One limitation, there is no direct way to detect that an application has been restored from the tray menu this page provides a solution.
More functionality is added to menu items using the versatile function wb_exec(). This function runs external programs with the option to pass parameters.
This page concludes the tutorial with a fully working alternative controller.
Download and Install
The plugin is independent of Uniform Server and may be extracted to any location.
However if you wish to run the alternative control interface example it must be extracted to Uniform Server’s plugin folder as explained below.
- Download file V55_WINBINDER_531VC6TS_1.0.exe from SourceForge
- Save the file to folder UniServer\plugins
- To extract files, double click on file V55_WINBINDER_531VC6TS_1.0.exe, no need to change the path.
- If you wish to save space delete V55_WINBINDER_531VC6TS_1.0.exe
- Download file V55_WINBINDER_531VC6TS_1.0.zip from SourceForge
- Save to any folder (e.g. temp1)
- Extract files, navigate to folder winbinder
- Copy winbinder to Uniform Server's folder UniServer\plugins.
- If you wish to save space delete temp1
WinBinder extension compatibility
Please note the WinBinder extension php_winbinder.dll is compatible across a PHP series
that means the included dll will run on PHP versions 5.3.0, 5.3.1 and 5.3.2RC1 etc
The plugin has the following file-folder structure:
|winbinder||Main Plugin folder||NOTES|
|bat2exe||Bat to exe converter folder|
|Bat_To_Exe_Converter.exe||Utility program that converts bat to exe||From Fatih Kodak|
|Help [English].chm||Utility documentation||From Fatih Kodak|
|uslogo.ico||icon for exe - optional (use your own)|
|test_1.bat||Batch file to run test_1.phpwb||See Wiki|
|test_1.phpwb||First Tutorial example||See Wiki|
|php.exe||CLI command line interface||From PHP 5.3.1|
|php-win.exe||CLI command line interface (hidden)||From PHP 5.3.1|
|php5ts.dll||PHP Script Interpreter||From PHP 5.3.1|
|php-wb.ini||PHP configuration file for WinBinder||Edit this to add extensions|
|ssleay32.dll||cURL support||From PHP 5.3.1|
|libeay32.dll||cURL support||From PHP 5.3.1|
|extensions||PHP extensions folder|
|php_winbinder.dll||WinBinder extention||From WinBinder.org; see above.|
|php_curl.dll||From PHP 5.3.1|
|include||WinBinder includes folder;|
|wb_generic.inc.php||General-purpose supporting functions||From WinBinder-0.46.0.zip|
|wb_resources.inc.php||RC file parser: convert Windows resource file to WinBinder commands||From WinBinder-0.46.0.zip|
|wb_windows.inc.php||Windows functions||From WinBinder-0.46.0.zip|
|winbinder.php||Main inclusion file for WinBinder||From WinBinder-0.46.0.zip|
|resources||WinBinder image resources folder||From WinBinder-0.46.0.zip|
Adding PHP extensions
- Copy additional PHP extensions to folder UniServer\plugins\winbinder\php\extensions
- Edit file UniServer\plugins\winbinder\php\php-wb.ini
The file contains the following:
[PHP] extension=php_winbinder.dll extension=php_curl.dll extension_dir = "./extensions" error_reporting = E_ALL | E_STRICT date.timezone = "Europe/London"
Add lines similar to the first line (enables an extension)
Modification to winbinder.php
When WinBinder was written, PHP 5.3.1 did not exist hence the file UniServer\plugins\winbinder\php\include\winbinder.php has been modified to remove PHP version checking. The following section was removed:
$supported_php_version = preg_match( '"^(' . '4\.(3\.(10|11)|4\..)' . '|' . '5\.(1\.[3-5]|1\..)' . ')$"', PHP_VERSION ); if (!$supported_php_version) die("WinBinder does only support the following PHP versions:\n" . "- 4.3.10 up to excluding 5.0.0\n- 5.0.3 up to excluding 6.0.0\n");
This section is included for completeness. It provides details on where to obtain the plugin components.
Bat To Exe Converter
A utility to convert a batch file to an executable. Although not open source, it is an excellent freeware utility.
Download Bat To Exe Converter version 126.96.36.199, dated 18.02.2009
WinBinder is an extension to PHP for building native Windows graphical user interfaces. Although currently at alpha design stage, it is fully functional. A minor change is required to disable the PHP version check.
Uniform Server's WinBinder plugin is a minimal solution. See the download for a complete version of WinBinder.
A core component of WinBinder is the PHP extension php_winbinder.dll Be sure you use a compiled extension that matches the version of PHP.
- The binary used in this plugin was compiled by Alec Gorge (WinBinder forum name "alecgorge") (Sun Dec 13, 2009 4:05 am) found on the above page
- Download page http://www.mediafire.com/?3g2dwayg4zm
- Compiled for PHP 5.3.1 V6 TS
Alec's web site is Ramblingwood
The following components are required obtain these from the full PHP 5.3.1 package or from Uniform Server 5.5-Nano:
Depending on your Windows application requirements you may require additional extensions hence its worth downloading a full version of PHP.
The above introduction to WinBinder shows how easy the plugin is to install.
Each Windows application starts with a basic script (template) covered on the next page.