RSSAminetKontakt

Home/Seiten/server_cmd.php

server_cmd.php, Sonntag, 12. November 2017 16:23
<?php
class procstream {
	public function __construct($cmd,$parse) {
		$this->cmd = $cmd;
		$this->func = $parse;
		$this->descriptorspec = array(
		   0 => array("pipe", "r"),
		   1 => array("pipe", "w"),
		   2 => array("pipe", "w")
		);
		$this->open();
	}
	public function parse($string) {
		call_user_func($this->func, $string);
	}
	public function close() {
		fclose($this->pipes[0]);
		fclose($this->pipes[1]);
		fclose($this->pipes[2]);
		proc_close($this->process);
	}

	public function open() {
		$this->process = proc_open(escapeshellcmd($this->cmd), $this->descriptorspec, $this->pipes);
		if (is_resource($this->process)) {
			stream_set_blocking($this->pipes[1], 0);
			stream_set_blocking($this->pipes[2], 0);
		}
	}
	public function select() {
		$read   = array($this->pipes[1],$this->pipes[2]);
		$i = NULL;
		$num_changed_stream = stream_select($read, $i, $i, 1);
		if ($num_changed_stream > 0) {
			foreach($read as $sk) {
				$this->parse(stream_get_contents($sk));
			}
		}		
	}
	public function send($string) {
		fwrite($this->pipes[0], "$string");
	}
}
?>
Erstellt von: Robin Hüskes
Erstellt am: Sonntag, 12. November 2017 16:23
Geändert von: Robin Hüskes
Geändert am: Sonntag, 12. November 2017 16:23
Zum Live Linux: