1.0.0 2015-08-19 04:22 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:34:56 UTC


README

Latest Stable Version Latest Stable Version Total Downloads License

执行一个命令,并提供对程序执行的高级控制。

要求

  • PHP >= 5.3.0

简介

使用 composer composer.json

"require": {
	"cloudmario/yeah": "dev-master"
}

用法

  • 简单
$p = new Yeah("/bin/bash");
list($pid, $stdin, $stdout, $stderr) = array($p->pid(), $p->stdin(), $p->stdout(), $p->stderr());

fwrite($stdin, "echo 42.out\n");
fwrite($stdin, "echo 42.err 1>&2\n");
fclose($stdin);

echo "pid    : " . $pid."\n";
echo "stdout : " . trim(fread($stdout, 1024)) . "\n";
echo "stderr : " . trim(fread($stderr, 1024)) . "\n";
echo "status : " . trim(print_r($p->status(), true)) . "\n";
$status = Yeah::yeah("/bin/bash", function($pid, $stdin, $stdout, $stderr) {
	
	fwrite($stdin, "echo 42.out\n");
	fwrite($stdin, "echo 42.err 1>&2\n");
	fclose($stdin);

	echo "pid    : " . $pid . "\n";
	echo "stdout : " . trim(fread($stdout, 1024)) . "\n";
	echo "stderr : " . trim(fread($stderr, 1024)) . "\n";
	
	/*
	while ( !feof($stdout) ) {
		$out .= fgets($stdout, 2048);
	}
	*/
	
});

echo "status : " . trim(print_r($status, true)) . "\n";