AloFramework documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alo
    • Cache
    • CLI
    • Controller
    • Db
    • Exception
    • FileSystem
    • Session
    • Statics
    • Test
    • Validators
    • Windows
  • Controller
  • None
  • PHP

Classes

  • Service
 1 <?php
 2    namespace Alo\Windows;
 3 
 4    use Alo\Exception\OSException;
 5 
 6    if(!defined('GEN_START')) {
 7       http_response_code(404);
 8       die();
 9    } elseif(!server_is_windows()) {
10       throw new OSException('The service manager is only supported on Windows.');
11    }
12 
13    /**
14     * Windows service handler
15     *
16     * @author Art <a.molcanovas@gmail.com>
17     */
18    abstract class Service {
19 
20       /**
21        * Checks if a service exists
22        *
23        * @author Art <a.molcanovas@gmail.com>
24        *
25        * @param string $name Service name
26        *
27        * @return bool
28        */
29       static function exists($name) {
30          return trim(shell_exec(DIR_SYS . 'bin' . DIRECTORY_SEPARATOR . 'serviceexists.bat ' . $name)) == 'OK';
31       }
32 
33       /**
34        * Deletes a service
35        *
36        * @author Art <a.molcanovas@gmail.com>
37        *
38        * @param string $name Service name
39        *
40        * @return string shell_exec() output
41        */
42       static function delete($name) {
43          return self::stop($name) . PHP_EOL . shell_exec('sc delete ' . $name);
44       }
45 
46       /**
47        * Stops a service
48        *
49        * @author Art <a.molcanovas@gmail.com>
50        *
51        * @param string $name Service name
52        *
53        * @return string shell_exec() output
54        */
55       static function stop($name) {
56          return shell_exec('sc stop ' . $name);
57       }
58 
59       /**
60        * Starts a service
61        *
62        * @author Art <a.molcanovas@gmail.com>
63        *
64        * @param string $name Service name
65        *
66        * @return string shell_exec() output
67        */
68       static function start($name) {
69          return shell_exec('sc start ' . $name);
70       }
71 
72       /**
73        * Installes a service from an executable
74        *
75        * @author Art <a.molcanovas@gmail.com>
76        *
77        * @param string      $service_name The name of the service
78        * @param string      $exe_path     Path to the executable
79        * @param null|string $display_name Optionally, a custom display name for the service
80        *
81        * @return string shell_exec() output
82        */
83       static function installExe($service_name, $exe_path, $display_name = null) {
84          $cmd = 'sc create ' . $service_name . ' binPath= "' . $exe_path . '"';
85 
86          if($display_name) {
87             $cmd .= ' DisplayName= "' . $display_name . '"';
88          }
89 
90          return shell_exec($cmd);
91       }
92    }
AloFramework documentation API documentation generated by ApiGen 2.8.0