source: trunk/Packages/Common/Process.php

Last change on this file was 8, checked in by chronos, 19 months ago
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
File size: 1.2 KB
Line 
1<?php
2
3class Process
4{
5 public string $Command;
6 public $Handle;
7 public array $Pipes;
8 public array $Environment;
9 public ?string $WorkingDir;
10
11 function __construct()
12 {
13 $this->Command = '';
14 $this->Handle = null;
15 $this->Pipes = array();
16 $this->Environment = array();
17 $this->WorkingDir = null;
18 }
19
20 function Start(): void
21 {
22 if (!$this->IsRunning())
23 {
24 $DescriptorSpec = array(
25 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
26 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
27 2 => array("pipe", "w") // stderr is a pipe that the child will write to
28 );
29
30 $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes,
31 $this->WorkingDir, $this->Environment);
32 stream_set_blocking($this->Pipes[0], FALSE);
33 stream_set_blocking($this->Pipes[1], FALSE);
34 stream_set_blocking($this->Pipes[2], FALSE);
35 }
36 }
37
38 function Stop(): void
39 {
40 if ($this->IsRunning())
41 {
42 proc_close($this->Handle);
43 $this->Handle = null;
44 }
45 }
46
47 function IsRunning(): bool
48 {
49 return is_resource($this->Handle);
50 }
51}
Note: See TracBrowser for help on using the repository browser.