本文整理汇总了PHP中proc_close函数的典型用法代码示例。如果您正苦于以下问题:PHP proc_close函数的具体用法?PHP proc_close怎么用?PHP proc_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了proc_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sync_object
function sync_object($object_type, $object_name)
{
# Should only provide error information on stderr: put stdout to syslog
$cmd = "geni-sync-wireless {$object_type} {$object_name}";
error_log("SYNC(cmd) " . $cmd);
$descriptors = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
$process = proc_open($cmd, $descriptors, $pipes);
$std_output = stream_get_contents($pipes[1]);
# Should be empty
$err_output = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$proc_value = proc_close($process);
$full_output = $std_output . $err_output;
foreach (split("\n", $full_output) as $line) {
if (strlen(trim($line)) == 0) {
continue;
}
error_log("SYNC(output) " . $line);
}
if ($proc_value != RESPONSE_ERROR::NONE) {
error_log("WIRELESS SYNC error: {$proc_value}");
}
return $proc_value;
}
示例2: __construct
/**
* Constructor.
*
* @param Horde_Vcs_Base $rep A repository object.
* @param string $dn Path to the directory.
* @param array $opts Any additional options:
*
* @throws Horde_Vcs_Exception
*/
public function __construct(Horde_Vcs_Base $rep, $dn, $opts = array())
{
parent::__construct($rep, $dn, $opts);
$cmd = $rep->getCommand() . ' ls ' . escapeshellarg($rep->sourceroot . $this->_dirName);
$dir = proc_open($cmd, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
if (!$dir) {
throw new Horde_Vcs_Exception('Failed to execute svn ls: ' . $cmd);
}
if ($error = stream_get_contents($pipes[2])) {
proc_close($dir);
throw new Horde_Vcs_Exception($error);
}
/* Create two arrays - one of all the files, and the other of all the
* dirs. */
$errors = array();
while (!feof($pipes[1])) {
$line = chop(fgets($pipes[1], 1024));
if (!strlen($line)) {
continue;
}
if (substr($line, 0, 4) == 'svn:') {
$errors[] = $line;
} elseif (substr($line, -1) == '/') {
$this->_dirs[] = substr($line, 0, -1);
} else {
$this->_files[] = $rep->getFile($this->_dirName . '/' . $line);
}
}
proc_close($dir);
}
示例3: GetMime
/**
* Gets the mime type for a blob
*
* @param GitPHP_Blob $blob blob
* @return string mime type
*/
public function GetMime($blob)
{
if (!$blob) {
return false;
}
$data = $blob->GetData();
if (empty($data)) {
return false;
}
$descspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
$proc = proc_open('file -b --mime -', $descspec, $pipes);
if (is_resource($proc)) {
fwrite($pipes[0], $data);
fclose($pipes[0]);
$mime = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($proc);
if ($mime && strpos($mime, '/')) {
if (strpos($mime, ';')) {
$mime = strtok($mime, ';');
}
return $mime;
}
}
return false;
}
示例4: collectProcessGarbage
private function collectProcessGarbage()
{
foreach ($this->processes as $key => $procHandle) {
$info = proc_get_status($procHandle);
if ($info["running"]) {
continue;
}
$this->defunctProcessCount--;
proc_close($procHandle);
unset($this->processes[$key]);
if ($this->expectedFailures > 0) {
$this->expectedFailures--;
continue;
}
if (!$this->stopPromisor) {
$this->spawn();
}
}
// If we've reaped all known dead processes we can stop checking
if (empty($this->defunctProcessCount)) {
\Amp\disable($this->procGarbageWatcher);
}
if ($this->stopPromisor && empty($this->processes)) {
\Amp\cancel($this->procGarbageWatcher);
if ($this->stopPromisor !== true) {
\Amp\immediately([$this->stopPromisor, "succeed"]);
}
$this->stopPromisor = true;
}
}
示例5: run
/**
* Execute the given command
*
* @param string $command Command to execute
* @param array $args Arguments for command
*
* @return mixed $return Command output
*/
public function run($command, $args = null)
{
Output::msg('Executing command: "' . $command . '"');
// filter the command
$command = escapeshellcmd($command);
$descSpec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$pipes = null;
$return = null;
$process = proc_open($command, $descSpec, $pipes);
if (is_resource($process)) {
$return = stream_get_contents($pipes[1]);
if (empty($return)) {
// probably some sort of error
if (is_resource($pipes[2])) {
$err = trim(stream_get_contents($pipes[2]));
fclose($pipes[2]);
throw new \Exception($err);
}
}
fclose($pipes[1]);
$returnCode = proc_close($process);
Output::msg("Execution result:\n" . $return);
}
return $return;
}
示例6: execute
/**
* Execute this command.
*
* @return int Error code returned by the subprocess.
*
* @task command
*/
public function execute()
{
$command = $this->command;
$profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(array('type' => 'exec', 'subtype' => 'passthru', 'command' => $command));
$spec = array(STDIN, STDOUT, STDERR);
$pipes = array();
if ($command instanceof PhutilCommandString) {
$unmasked_command = $command->getUnmaskedString();
} else {
$unmasked_command = $command;
}
$env = $this->env;
$cwd = $this->cwd;
$options = array();
if (phutil_is_windows()) {
// Without 'bypass_shell', things like launching vim don't work properly,
// and we can't execute commands with spaces in them, and all commands
// invoked from git bash fail horridly, and everything is a mess in
// general.
$options['bypass_shell'] = true;
}
$trap = new PhutilErrorTrap();
$proc = @proc_open($unmasked_command, $spec, $pipes, $cwd, $env, $options);
$errors = $trap->getErrorsAsString();
$trap->destroy();
if (!is_resource($proc)) {
throw new Exception(pht('Failed to passthru %s: %s', 'proc_open()', $errors));
}
$err = proc_close($proc);
$profiler->endServiceCall($call_id, array('err' => $err));
return $err;
}
示例7: printFax
function printFax($fax_id)
{
$data = $GLOBALS['hylax_storage']->getFaxData($fax_id);
$command = $GLOBALS['conf']['fax']['print'];
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
/* Set up the process. */
$process = proc_open($command, $descriptorspec, $pipes);
if (!is_resource($process)) {
return PEAR::raiseError('fail');
}
fwrite($pipes[0], $data);
fclose($pipes[0]);
$output = '';
while (!feof($pipes[1])) {
$output .= fgets($pipes[1], 1024);
}
fclose($pipes[1]);
$stderr = '';
while (!feof($pipes[2])) {
$stderr .= fgets($pipes[2], 1024);
}
fclose($pipes[2]);
proc_close($process);
if ($stderr) {
return PEAR::raiseError($stderr);
}
return true;
}
示例8: evaluate
/**
* Evaluates the constraint for parameter $other. Returns TRUE if the
* constraint is met, FALSE otherwise.
*
* @param mixed $other Filename of the image to compare.
* @return bool
* @abstract
*/
public function evaluate($other)
{
if (!is_string($other) || !is_file($other) || !is_readable($other)) {
throw new ezcBaseFileNotFoundException($other);
}
$descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
$command = sprintf('compare -metric MAE %s %s null:', escapeshellarg($this->filename), escapeshellarg($other));
$imageProcess = proc_open($command, $descriptors, $pipes);
// Close STDIN pipe
fclose($pipes[0]);
$errorString = '';
// Read STDERR
do {
$errorString .= rtrim(fgets($pipes[2], 1024), "\n");
} while (!feof($pipes[2]));
$resultString = '';
// Read STDOUT
do {
$resultString .= rtrim(fgets($pipes[1], 1024), "\n");
} while (!feof($pipes[1]));
// Wait for process to terminate and store return value
$return = proc_close($imageProcess);
// Some versions output to STDERR
if (empty($resultString) && !empty($errorString)) {
$resultString = $errorString;
}
// Different versuions of ImageMagick seem to output "dB" or not
if (preg_match('/([\\d.,e]+)(\\s+dB)?/', $resultString, $match)) {
$this->difference = (int) $match[1];
return $this->difference <= $this->delta;
}
return false;
}
示例9: executeCommand
/**
* Executes shell commands.
* @param array $args
* @return bool Indicates success
*/
public function executeCommand($args = array())
{
$this->lastOutput = array();
$command = call_user_func_array('sprintf', $args);
if ($this->quiet) {
$this->logger->log('Executing: ' . $command);
}
$status = 0;
$descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
$pipes = array();
$process = proc_open($command, $descriptorSpec, $pipes, dirname($this->buildPath), null);
if (is_resource($process)) {
fclose($pipes[0]);
$this->lastOutput = stream_get_contents($pipes[1]);
$this->lastError = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$status = proc_close($process);
}
$this->lastOutput = array_filter(explode(PHP_EOL, $this->lastOutput));
$shouldOutput = $this->logExecOutput && ($this->verbose || $status != 0);
if ($shouldOutput && !empty($this->lastOutput)) {
$this->logger->log($this->lastOutput);
}
if (!empty($this->lastError)) {
$this->logger->log("[0;31m" . $this->lastError . "[0m", LogLevel::ERROR);
}
$rtn = false;
if ($status == 0) {
$rtn = true;
}
return $rtn;
}
示例10: stream
public function stream(Git_HTTP_Command $command)
{
$cwd = '/tmp';
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
if (ForgeConfig::get('sys_logger_level') == Logger::DEBUG) {
$descriptorspec[2] = array('file', ForgeConfig::get('codendi_log') . '/git_http_error_log', 'a');
}
$pipes = array();
$this->logger->debug('Command: ' . $command->getCommand());
$this->logger->debug('Environment: ' . print_r($command->getEnvironment(), true));
$process = proc_open($command->getCommand(), $descriptorspec, $pipes, $cwd, $command->getEnvironment());
if (is_resource($process)) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
fwrite($pipes[0], file_get_contents('php://input'));
}
fclose($pipes[0]);
$first = true;
while ($result = stream_get_contents($pipes[1], self::CHUNK_LENGTH)) {
if ($first) {
list($headers, $body) = http_split_header_body($result);
foreach (explode("\r\n", $headers) as $header) {
header($header);
}
file_put_contents('php://output', $body);
} else {
file_put_contents('php://output', $result);
}
$first = false;
}
fclose($pipes[1]);
$return_value = proc_close($process);
}
}
示例11: render
public function render()
{
// Generate the DOT source code, and write to a file.
$dot = new \Tabulate\Template('erd/erd.twig');
$dot->tables = $this->tables;
$dot->selectedTables = $this->selectedTables;
$dotCode = $dot->render();
$tmpFilePath = Config::storageDirTmp('erd/' . uniqid());
$dotFile = $tmpFilePath . '/erd.dot';
$pngFile = $tmpFilePath . '/erd.png';
file_put_contents($dotFile, $dotCode);
// Generate the image.
$cmd = Config::dotCommand() . ' -Tpng -o' . escapeshellarg($pngFile) . ' ' . escapeshellarg($dotFile);
$ds = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$pipes = false;
$proc = proc_open($cmd, $ds, $pipes, Config::storageDirTmp('erd'), array());
fclose($pipes[0]);
$out = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$err = stream_get_contents($pipes[2]);
fclose($pipes[2]);
proc_close($proc);
if (!empty($err)) {
throw new \Exception("Error generating graph image. {$err}");
}
// Send the image.
header('Content-Type:image/png');
echo file_get_contents($pngFile);
// Clean up.
\Tabulate\File::rmdir($tmpFilePath);
}
示例12: execute
private function execute($args, $pipe_stdout, $cwd_override = null)
{
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
$cwd = $cwd_override != NULL ? $cwd_override : $this->cwd;
$cmd = join(' ', array_map('escapeshellarg', $args));
$proc = proc_open($cmd, $descriptorspec, $pipes, $cwd, array('LANG' => 'en_US.UTF-8'));
if (!is_resource($proc)) {
$errors = error_get_last();
$this->log->error("{$cmd} failed: {$errors['type']} {$errors['message']}");
throw new Exception($errors['message']);
}
fclose($pipes[0]);
if ($pipe_stdout) {
$output = stream_get_contents($pipes[1]);
} else {
fpassthru($pipes[1]);
$output = null;
}
$err = stream_get_contents($pipes[2]);
$retval = proc_close($proc);
if ($retval != 0) {
$this->log->error("{$cmd} failed: {$retval} {$output} {$err}");
throw new Exception($err);
}
return $output;
}
示例13: cs2cs_core2
function cs2cs_core2($lat, $lon, $to)
{
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
if (mb_eregi('^[a-z0-9_ ,.\\+\\-=]*$', $to) == 0) {
die("invalid arguments in command: " . $to . "\n");
}
$command = CS2CS . " +proj=latlong +ellps=WGS84 +to " . $to;
$process = proc_open($command, $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $lon . " " . $lat);
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
//
// $procstat = proc_get_status($process);
//
// neither proc_close nor proc_get_status return reasonable results with PHP5 and linux 2.6.11,
// see http://bugs.php.net/bug.php?id=32533
//
// as temporary (?) workaround, check stderr output.
// (Vinnie, 2006-02-09)
if ($stderr) {
die("proc_open() failed:<br />command='{$command}'<br />stderr='" . $stderr . "'");
}
proc_close($process);
return mb_split("\t|\n| ", mb_trim($stdout));
} else {
die("proc_open() failed, command={$command}\n");
}
}
示例14: __invoke
/**
* Launch PHP's built-in web server for this specific WordPress installation.
*
* Uses `php -S` to launch a web server serving the WordPress webroot.
* <http://php.net/manual/en/features.commandline.webserver.php>
*
* ## OPTIONS
*
* [--host=<host>]
* : The hostname to bind the server to.
* ---
* default: localhost
* ---
*
* [--port=<port>]
* : The port number to bind the server to.
* ---
* default: 8080
* ---
*
* [--docroot=<path>]
* : The path to use as the document root.
*
* [--config=<file>]
* : Configure the server with a specific .ini file.
*
* ## EXAMPLES
*
* # Make the instance available on any address (with port 8080)
* $ wp server --host=0.0.0.0
* PHP 5.6.9 Development Server started at Tue May 24 01:27:11 2016
* Listening on http://0.0.0.0:8080
* Document root is /
* Press Ctrl-C to quit.
*
* # Run on port 80 (for multisite)
* $ sudo wp server --host=localhost.localdomain --port=80
* PHP 5.6.9 Development Server started at Tue May 24 01:30:06 2016
* Listening on http://localhost1.localdomain1:8080
* Document root is /
* Press Ctrl-C to quit.
*
* # Configure the server with a specific .ini file
* $ wp server --config=development.ini
* PHP 7.0.9 Development Server started at Mon Aug 22 12:09:04 2016
* Listening on http://localhost:8080
* Document root is /
* Press Ctrl-C to quit.
*
* @when before_wp_load
*/
function __invoke($_, $assoc_args)
{
$min_version = '5.4';
if (version_compare(PHP_VERSION, $min_version, '<')) {
WP_CLI::error("The `wp server` command requires PHP {$min_version} or newer.");
}
$defaults = array('host' => 'localhost', 'port' => 8080, 'docroot' => false, 'config' => get_cfg_var('cfg_file_path'));
$assoc_args = array_merge($defaults, $assoc_args);
$docroot = $assoc_args['docroot'];
if (!$docroot) {
$config_path = WP_CLI::get_runner()->project_config_path;
if (!$config_path) {
$docroot = ABSPATH;
} else {
$docroot = dirname($config_path);
}
}
$cmd = \WP_CLI\Utils\esc_cmd('%s -S %s -t %s -c %s %s', PHP_BINARY, $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, $assoc_args['config'], \WP_CLI\Utils\extract_from_phar(WP_CLI_ROOT . '/php/router.php'));
$descriptors = array(STDIN, STDOUT, STDERR);
// https://bugs.php.net/bug.php?id=60181
$options = array();
if (\WP_CLI\Utils\is_windows()) {
$options["bypass_shell"] = TRUE;
}
exit(proc_close(proc_open($cmd, $descriptors, $pipes, NULL, NULL, $options)));
}
示例15: scan
protected function scan($fileView, $filepath)
{
$this->status = new Status();
$fhandler = $this->getFileHandle($fileView, $filepath);
\OCP\Util::writeLog('files_antivirus', 'Exec scan: ' . $filepath, \OCP\Util::DEBUG);
// using 2>&1 to grab the full command-line output.
$cmd = escapeshellcmd($this->avPath) . " - 2>&1";
$descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
$pipes = array();
$process = proc_open($cmd, $descriptorSpec, $pipes);
if (!is_resource($process)) {
fclose($fhandler);
throw new \RuntimeException('Error starting process');
}
// write to stdin
$shandler = $pipes[0];
while (!feof($fhandler)) {
$chunk = fread($fhandler, $this->chunkSize);
fwrite($shandler, $chunk);
}
fclose($shandler);
fclose($fhandler);
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$result = proc_close($process);
$this->status->parseResponse($output, $result);
return $this->status->getNumericStatus();
}