source: trunk/Packages/Common/Process.php

Last change on this file was 63, checked in by chronos, 4 years ago
  • Modified: Used explicit types where possible for better error reporting.
  • Modified: Updated Common packaged to newer version.
  • Modified: Simplified pages title.
  • Added: Simple keyword based spam filter for meet items.
File size: 1.2 KB
RevLine 
[56]1<?php
2
3class Process
4{
[63]5 public string $Command;
6 public $Handle;
7 public array $Pipes;
8 public array $Environment;
9 public ?string $WorkingDir;
10
[56]11 function __construct()
12 {
13 $this->Command = '';
14 $this->Handle = null;
15 $this->Pipes = array();
16 $this->Environment = array();
17 $this->WorkingDir = null;
18 }
[63]19
20 function Start(): void
[56]21 {
[63]22 if (!$this->IsRunning())
[56]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
[63]30 $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes,
[56]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 }
[63]37
38 function Stop(): void
[56]39 {
[63]40 if ($this->IsRunning())
[56]41 {
42 proc_close($this->Handle);
43 $this->Handle = null;
44 }
45 }
[63]46
47 function IsRunning(): bool
[56]48 {
[63]49 return is_resource($this->Handle);
[56]50 }
51}
Note: See TracBrowser for help on using the repository browser.