487
edits
(New page: {{Nav PHP WinBinder}} '''''Alternative control part 2''''' This page is a continuation of the alternative control. It covers starting and stopping Apache and MySQL servers from a windows ...) |
(Proofreading and grammatical changes; some minor reformatting) |
||
Line 2: | Line 2: | ||
'''''Alternative control part 2''''' | '''''Alternative control part 2''''' | ||
This page is a continuation of the alternative control. It covers starting and stopping Apache and MySQL servers from a | This page is a continuation of the alternative control. It covers starting and stopping Apache and MySQL servers from a Windows application. | ||
== Initial Problem == | == Initial Problem == | ||
Starting or stopping a server | Starting or stopping a server spawns a separate process. This allows the main application to continue executing uninterrupted. An implication of this, other than monitoring a server’s status is that there is no way to determine when it completes. | ||
What is required is a timer to periodically check a server’s status. This can be handled by using a timer control. | |||
For example: | |||
Add this to the constants define("ID_APP_TIMER", 9001); | Add this to the constants: define("ID_APP_TIMER", 9001); | ||
Add this to create control section | Add this to create control section | ||
Line 17: | Line 17: | ||
wb_create_timer($mainwin, ID_APP_TIMER, 100); // One second interval | wb_create_timer($mainwin, ID_APP_TIMER, 100); // One second interval | ||
</pre> | </pre> | ||
The above produces a 100ms tick. Every 100ms calls the handler function | The above produces a 100ms tick. Every 100ms it calls the handler function. | ||
The handler function contains this code which in turn calls our main_timer() function | The handler function contains this code, which in turn calls our main_timer() function. | ||
<pre> | <pre> | ||
// Main timer tick call other functions | // Main timer tick call other functions | ||
Line 28: | Line 28: | ||
A timer must be specifically killed using function wb_destroy_timer($window, ID); | A timer must be specifically killed using function wb_destroy_timer($window, ID); | ||
Add | Add this to the close window section as shown below: | ||
<pre> | <pre> | ||
case IDCLOSE: // Constant IDCLOSE (8) predefined | case IDCLOSE: // Constant IDCLOSE (8) predefined | ||
Line 35: | Line 35: | ||
break; | break; | ||
</pre> | </pre> | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
== Timer function main_timer() == | == Timer function main_timer() == | ||
The timer function contains four sections corresponding to Apache start/stop and MySQL start/stop | The timer function contains four sections corresponding to Apache start/stop and MySQL start/stop. | ||
Each section has the following format: | Each section has the following format: | ||
Line 49: | Line 49: | ||
} | } | ||
</pre> | </pre> | ||
Variable $Start_timer_1 is a global allowing its value to be retained between calls to this function. | Variable $Start_timer_1 is a global, allowing its value to be retained between calls to this function. | ||
The complete function code as follows: | The complete function code as follows: | ||
Line 95: | Line 95: | ||
//====================================================== Main Timer handler === | //====================================================== Main Timer handler === | ||
</pre> | </pre> | ||
=== Global Variables === | === Global Variables === | ||
The global variables need to be defined at the top of the main script | The global variables need to be defined at the top of the main script. | ||
Add the following just above constants | Add the following just above constants | ||
Line 120: | Line 120: | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
== Server main functions == | == Server main functions == | ||
For a Windows application the main server functions stop_servers.php and start_servers.php require some modifications | For a Windows application, the main server functions stop_servers.php and start_servers.php require some modifications. | ||
These were copied from folder UniServer\unicon\main their names changed to stop_servers.inc.php and start_servers.inc.php | These were copied from folder UniServer\unicon\main and their names were changed to stop_servers.inc.php and start_servers.inc.php | ||
They had a quick clean up and a wait function added wb_wait($window,2000) to allow Windows to start processing. Probably the time is excessive and can be reduced. You can twiddle with the value | They had a quick clean up and a wait function added wb_wait($window,2000) to allow Windows to start processing. Probably the time is excessive and can be reduced. You can twiddle with the value. What's important is to add these with an include staetment. | ||
Add the last two lines as shown | Add the last two lines as shown | ||
Line 136: | Line 135: | ||
include "stop_servers.inc.php"; | include "stop_servers.inc.php"; | ||
</pre> | </pre> | ||
With these | With these functions added, we can continue adding more capability. | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
== Push Buttons == | == Push Buttons == | ||
Buttons provide a user interface that can easily be abused. By this I mean that a user is not restricted. They can click buttons in any order and even double click. | |||
For some application this may or may not be an issue | For some application this may or may not be an issue. Attempting to start or stop servers in quick succession can produce undesirable effects. Similarly if a server is not running, the associated buttons, if clicked, will again produce undesirable results. | ||
Similarly if a server is not running associated buttons if clicked will again produce undesirable results. | |||
A neat solution is to disable any buttons until their functionality can be guaranteed. | A neat solution is to disable any buttons until their functionality can be guaranteed. | ||
=== Server All Start/Stop === | === Server All Start/Stop === | ||
{| | {| | ||
|- | |- | ||
| | | | ||
The code on the right is added to the Handler Function. It is self-explanatory. | |||
Depending on the button caption text, the servers are either started or stopped. Appropriate buttons are disabled. | |||
Depending on the button caption text the servers are either started or stopped. | |||
Appropriate buttons are disabled. | |||
A timer started and server either started or stopped. The parameter passed is binary coded 1=Apache, 2=MySQL 3=Both | A timer is started and the server is either started or stopped. The parameter passed is binary coded: 1=Apache, 2=MySQL 3=Both | ||
The timer function checks a server’s status. On detecting a state change, it calls the init functions. This sets the appropriate indicator and button states. | |||
| | | | ||
<pre> | <pre> | ||
Line 188: | Line 180: | ||
</pre> | </pre> | ||
|} | |} | ||
=== Apache Start/Stop === | === Apache Start/Stop === | ||
{| | {| | ||
|- | |- | ||
| | | | ||
The code on the right is added to the Handler Function. It is self-explanatory. | |||
Depending on the button caption text, the servers are either started or stopped. Appropriate buttons are disabled. | |||
A timer is started and the server is either started or stopped. The parameter passed is binary coded: 1=Apache, 2=MySQL 3=Both | |||
The timer function checks a server’s status. On detecting a state change, it calls the init functions. This sets the appropriate indicator and button states. | |||
| | | | ||
<pre> | <pre> | ||
Line 223: | Line 211: | ||
</pre> | </pre> | ||
|} | |} | ||
=== MySQL Start/Stop === | === MySQL Start/Stop === | ||
{| | {| | ||
|- | |- | ||
| | | | ||
Code on the right is added to the Handler Function | Code on the right is added to the Handler Function. It is self-explanatory. | ||
It is self-explanatory | |||
Appropriate buttons are disabled. | Depending on the button caption text, the servers are either started or stopped. Appropriate buttons are disabled. | ||
A timer started and server either started or stopped. The parameter passed is binary coded 1=Apache, 2=MySQL 3=Both | A timer is started and the server is either started or stopped. The parameter passed is binary coded: 1=Apache, 2=MySQL 3=Both | ||
The timer function checks a server’s status. On detecting a state change, it calls the init functions. This sets the appropriate indicator and button states. | |||
| | | | ||
<pre> | <pre> | ||
Line 258: | Line 241: | ||
</pre> | </pre> | ||
|} | |} | ||
=== Apanel === | === Apanel === | ||
{| | {| | ||
|- | |- | ||
| | | | ||
Code on the right is added to the Handler Function | Code on the right is added to the Handler Function. | ||
Note: Code is placed above the switch($id) statement | Note: Code is placed above the switch($id) statement. | ||
| | | | ||
<pre> | <pre> | ||
Line 281: | Line 263: | ||
</pre> | </pre> | ||
|} | |} | ||
=== phpMyAdmin === | === phpMyAdmin === | ||
Line 287: | Line 268: | ||
|- | |- | ||
| | | | ||
Code on the right is added to the Handler Function | Code on the right is added to the Handler Function. | ||
Note: Code is placed above the | Note: Code is placed above the switch($id) statement. | ||
| | | | ||
Line 306: | Line 287: | ||
</pre> | </pre> | ||
|} | |} | ||
=== My CMD === | === My CMD === | ||
Line 312: | Line 293: | ||
|- | |- | ||
| | | | ||
Code on the right is added to the Handler Function | Code on the right is added to the Handler Function. | ||
It is self-explanatory. | It is self-explanatory. | ||
Line 327: | Line 307: | ||
== Test == | == Test == | ||
To see this code in action run '''test_5.bat''' (code contained in test_5.phpw) | To see this code in action, run '''test_5.bat''' (code contained in test_5.phpw). | ||
Start and stop both servers again | Run Uniform Server, start and stop each server and observe the button and indicator states. | ||
Start and stop both servers, again observing the button and indicator states. | |||
After testing close both Servers and application script. | After testing, close both Servers and the application script. | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
Line 340: | Line 319: | ||
At this stage you have fully functional servers. | At this stage you have fully functional servers. | ||
The next step is to add functionality to the remaining buttons. This is covered on the [[PHP WinBinder: Alternative control 3 | '''next page''']]. | |||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' |