PHP WinBinder: Alternative control 2: Difference between revisions

Proofreading and grammatical changes; some minor reformatting
(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 windows application.
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, spawns a separate process, this allows the main application to continue executing uninterrupted.
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.


An implication of this, other than monitoring a server’s status there is no way to determine the time it completes.
What is required is a timer to periodically check a server’s status. This can be handled by using a timer control.  


What is required is a timer to periodically check a server’s status. This can be handled by using a timer control for example
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 the above line to the close window section as shown below  
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>
'''''[[#top | Top]]'''''
 
=== 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 whats importent is to add these with an include statment.
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 function added we can add more functionality.
With these functions added, we can continue adding more capability.


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Push Buttons ==
== Push Buttons ==
Button provide a user interface that can easily be abused by this I mean a user is not restricted they can click buttons in any order and even double click.
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 however attempting to start or stop servers in quick succession can produce undesirable effects.
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.


'''''[[#top | Top]]'''''
=== Server All Start/Stop ===
=== Server All Start/Stop ===
{|
{|
|-
|-
|
|
Code on the right is added to the Handler Function
The code on the right is added to the Handler Function. It is self-explanatory.


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


Timer function checks a server’s status, on detecting a state change calls the init functions this sets appropriate indicator and button states.
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>
|}
|}
'''''[[#top | Top]]'''''
 
=== Apache Start/Stop ===
=== Apache Start/Stop ===
{|
{|
|-
|-
|
|
Code on the right is added to the Handler Function
The code on the right is added to the Handler Function. It is self-explanatory.


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.
A timer is started and the server is either started or stopped. The parameter passed is binary coded: 1=Apache, 2=MySQL 3=Both


Appropriate buttons are disabled.
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.
 
A timer started and server either started or stopped. The parameter passed is binary coded 1=Apache, 2=MySQL 3=Both
 
Timer function checks a server’s status, on detecting a state change calls the init functions this sets appropriate indicator and button states.
|
|
<pre>
<pre>
Line 223: Line 211:
</pre>
</pre>
|}
|}
'''''[[#top | Top]]'''''
=== 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.
 
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


Timer function checks a server’s status, on detecting a state change calls the init functions this sets appropriate indicator and button states.
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>
|}
|}
'''''[[#top | Top]]'''''
=== 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>
|}
|}
'''''[[#top | Top]]'''''


=== 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 switch($id) statement
Note: Code is placed above the switch($id) statement.


|
|
Line 306: Line 287:
</pre>
</pre>
|}
|}
'''''[[#top | Top]]'''''
 


=== 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).
 
Run Uniform Server, start and stop each server observe button and indicator states.


Start and stop both servers again observe button and indicator states.   
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.


Next step is to add functionality to remaining buttons covered on the [[PHP WinBinder: Alternative control 3 | '''next page''']].
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]]'''''