logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Stoping / Starting Windows 7 service from PHP script
Author
zx9



Joined: 18 Mar 2009
Posts: 33
Location: uruguay

PostPosted: Mon 30 Apr '12 15:34    Post subject: Stoping / Starting Windows 7 service from PHP script Reply with quote

Here is an example to stop , make something, and resume service , Using extension "php_win32service.dll" found in Download Section.

Special thanks to Steffen for compiling (from source) this, for PHP 5.4.1 nts .

Admin note: Download removed, AL not supporting anymore PHP extensions.

More info in php.net : http://ar.php.net/manual/en/book.win32service.php


Code:
<?

$result = win32_query_service_status('MyService'); # take Flag fom service

# Service Flags:
# WIN32_SERVICE_CONTINUE_PENDING 0x00000005 La continuación del servicio está pendiente.
# WIN32_SERVICE_PAUSE_PENDING 0x00000006 La pausa del servicio está pendiente.
# WIN32_SERVICE_PAUSED 0x00000007 El servicio está pausado.
# WIN32_SERVICE_RUNNING 0x00000004 El servicio está en ejecución.
# WIN32_SERVICE_START_PENDING 0x00000002 El servicio está iniciado.
# WIN32_SERVICE_STOP_PENDING 0x00000003 El servicio está detenido.
# WIN32_SERVICE_STOPPED 0x00000001 El servicio no está en ejecución.


if($result['CurrentState']==1){   # if 'MyService' is stoped
 
  [Your code]

}else{   # If 'MyService' runing, stop it, wait for stoped flag, then continue
 
  win32_stop_service('MyService');  # stop 'MyService'
  $status = win32_query_service_status('MyService'); # take Flag fom service
 
   
    while($status['CurrentState']!=1){  # Loop to wait 'Stoped Flag'
       $status = win32_query_service_status('MyService'); # take Flag fom service
       usleep(3000);  # use 'usleep(xxx)' instead sleep(x) for below a second , in this I use 0.3 seconds to wait
    }

   [your code]
}

# Resume service
win32_start_service('MyService');
?>


Thanks Steffen and all people make this site useful
Back to top
dbpullman



Joined: 18 May 2012
Posts: 1

PostPosted: Fri 18 May '12 16:53    Post subject: Reply with quote

How are you running this compiled version of PHP? FastCGI, SAPI, mod_fcgi? I only ask because I've been trying to get win32service to work for a while. I've been able to get it to run Apache, but my main development server is IIS running FastCGI. I've heard that this extension will only work if running SAPI. Unfortunately php5isapi.dll no longer exists.

Please let me know! I've been banging my head on a wall with this for a while now! I've been reading and reading about how to compile an extension with PHP

Any answers/help would be greatly appreciated. Thanks!

Also, if possible could you maybe provide the compiled code, or at least let me know how I can compile the extension within PHP?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Tue 22 May '12 14:56    Post subject: Reply with quote

dbpullman wrote:
How are you running this compiled version of PHP? FastCGI, SAPI, mod_fcgi?


Steffen who compiled that module told that it works only with the CLI version, not with a server.

dbpullman wrote:

Also, if possible could you maybe provide the compiled code, or at least let me know how I can compile the extension within PHP?


Steffen may answer this, cause he made it.
Back to top
zx9



Joined: 18 Mar 2009
Posts: 33
Location: uruguay

PostPosted: Thu 24 May '12 3:27    Post subject: Reply with quote

James Blond wrote:
dbpullman wrote:
How are you running this compiled version of PHP? FastCGI, SAPI, mod_fcgi?


Steffen who compiled that module told that it works only with the CLI version, not with a server.


In zip file has for cgi no-CLI.
Work perfect for me
Back to top
maba



Joined: 05 Feb 2012
Posts: 64
Location: Germany, Heilbronn

PostPosted: Sat 21 Jul '12 19:10    Post subject: Reply with quote

Another option would be to use system calls with the sc command line tool:

system("sc stop MySQL"); // stopping for example MySQL
system("sc query MySQL"); // query the current state
system("sc start MySQL"); // starting MySQL

Yet another option: use COM and WMI.

Regards
maba
Back to top


Reply to topic   Topic: Stoping / Starting Windows 7 service from PHP script View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner