当前位置: 首页>>代码示例>>PHP>>正文


PHP proc_open函数代码示例

本文整理汇总了PHP中proc_open函数的典型用法代码示例。如果您正苦于以下问题:PHP proc_open函数的具体用法?PHP proc_open怎么用?PHP proc_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了proc_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:fboender,项目名称:gitphp,代码行数:32,代码来源:FileMimeType_FileExe.class.php

示例2: 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;
}
开发者ID:ahelsing,项目名称:geni-portal,代码行数:25,代码来源:wireless_operations.php

示例3: __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);
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:39,代码来源:Svn.php

示例4: __construct

 /**
  * Constructor
  *
  * @param   string command default NULL
  * @param   string[] arguments default []
  * @param   string cwd default NULL the working directory
  * @param   [:string] default NULL the environment
  * @throws  io.IOException in case the command could not be executed
  */
 public function __construct($command = NULL, $arguments = array(), $cwd = NULL, $env = NULL)
 {
     static $spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
     // For `new self()` used in getProcessById()
     if (NULL === $command) {
         return;
     }
     // Check whether the given command is executable.
     $binary = self::resolve($command);
     if (!is_file($binary) || !is_executable($binary)) {
         throw new IOException('Command "' . $binary . '" is not an executable file');
     }
     // Open process
     $cmd = CommandLine::forName(PHP_OS)->compose($binary, $arguments);
     if (!is_resource($this->_proc = proc_open($cmd, $spec, $pipes, $cwd, $env, array('bypass_shell' => TRUE)))) {
         throw new IOException('Could not execute "' . $cmd . '"');
     }
     $this->status = proc_get_status($this->_proc);
     $this->status['exe'] = $binary;
     $this->status['arguments'] = $arguments;
     $this->status['owner'] = TRUE;
     // Assign in, out and err members
     $this->in = new File($pipes[0]);
     $this->out = new File($pipes[1]);
     $this->err = new File($pipes[2]);
 }
开发者ID:Gamepay,项目名称:xp-framework,代码行数:35,代码来源:Process.class.php

示例5: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Starting server on port 5000');
     $descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
     $port = $input->getOption('port');
     // Start server process
     $process = proc_open("php -S localhost:{$port} -t public/ " . getcwd() . "/scripts/normal-server/router.php", $descriptorspec, $pipes, getcwd(), $_ENV);
     if (!is_resource($process)) {
         throw new Exception("popen error");
     }
     stream_set_blocking($pipes[0], 0);
     stream_set_blocking($pipes[1], 0);
     stream_set_blocking($pipes[2], 0);
     // Redirect all output
     while (!feof($pipes[1])) {
         foreach ($pipes as $pipe) {
             $line = fread($pipe, 128);
             if ($line) {
                 $output->writeln($line);
             }
         }
         sleep(0.5);
     }
     foreach ($pipes as $pipe) {
         fclose($pipe);
     }
 }
开发者ID:kiasaki,项目名称:vexillum,代码行数:27,代码来源:StartCommand.php

示例6: execi

function execi($cmd, $userdir, $timeout)
{
    $starttime = microtime();
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $cwd = getcwd() . "/" . $userdir;
    $env = null;
    $output = "";
    $proc = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
    $handle = fopen($userdir . "tempi.txt", "r");
    if ($handle) {
        while (($line = fgets($handle)) !== false) {
            fwrite($pipes[0], $line);
        }
        fclose($pipes[0]);
        fclose($handle);
    }
    while (microtime() < $starttime + $timeout) {
        $status = proc_get_status($proc);
        if ($status['running']) {
            if (is_resource($proc)) {
                $output = $output . "<pre>" . stream_get_contents($pipes[1]) . "</pre>";
                $output = $output . "<pre>" . stream_get_contents($pipes[2]) . "</pre>";
            }
        } else {
            $time = microtime() - $starttime;
            return $output . "  time to execute = " . $time;
            //command completed :)
        }
    }
    proc_terminate($proc);
    return 'timeout !!';
    // fwrite($pipes[0], '10');
    //  fclose($pipes[0]);
    // $return_value = proc_close($proc);
}
开发者ID:anikraj1994,项目名称:SimpleCompiler,代码行数:35,代码来源:compile.php

示例7: phutil_passthru

/**
 * Execute a command which takes over stdin, stdout and stderr, similar to
 * passthru(), but which preserves TTY semantics, escapes arguments, and is
 * traceable.
 *
 * @param  string  sprintf()-style command pattern to execute.
 * @param  ...     Arguments to sprintf pattern.
 * @return int     Return code.
 * @group exec
 */
function phutil_passthru($cmd)
{
    $args = func_get_args();
    $command = call_user_func_array('csprintf', $args);
    $profiler = PhutilServiceProfiler::getInstance();
    $call_id = $profiler->beginServiceCall(array('type' => 'exec', 'subtype' => 'passthru', 'command' => $command));
    $spec = array(STDIN, STDOUT, STDERR);
    $pipes = 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 = array('bypass_shell' => true);
        $proc = @proc_open($command, $spec, $pipes, null, null, $options);
    } else {
        $proc = @proc_open($command, $spec, $pipes);
    }
    if ($proc === false) {
        $err = 1;
    } else {
        $err = proc_close($proc);
    }
    $profiler->endServiceCall($call_id, array('err' => $err));
    return $err;
}
开发者ID:chaozhang80,项目名称:tool-package,代码行数:35,代码来源:execx.php

示例8: testExternalTest

 public function testExternalTest()
 {
     $dataDir = dirname(__FILE__) . "/data";
     $phpPath = isset($_SERVER["_"]) ? $_SERVER["_"] : "/bin/env php";
     $scriptFile = "{$dataDir}/syslog_tests.php";
     $desc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
     $proc = proc_open("'{$phpPath}' '{$scriptFile}'", $desc, $pipes);
     fclose($pipes[0]);
     fclose($pipes[1]);
     $ret = '';
     while (!feof($pipes[2])) {
         $ret .= fgets($pipes[2]);
     }
     $strings = explode("\n", $ret);
     // check each of the strings for correctness
     $regExp = "/ezctest\\S*: \\[Debug\\] \\[Donny\\] \\[quotes\\] I was bowling. \\(movie: The Big Lebowski\\)/";
     $this->assertRegExp($regExp, $strings[0]);
     $regExp = "/ezctest\\S*: \\[Debug\\] \\[Lebowski\\] \\[quotes\\] The dude abides./";
     $this->assertRegExp($regExp, $strings[1]);
     $regExp = "/ezctest\\S*: \\[Success audit\\] \\[Maude\\] \\[quotes\\] Don't be fatuous, Jeffrey./";
     $this->assertRegExp($regExp, $strings[2]);
     $regExp = "/ezctest\\S*: \\[Failed audit\\] \\[Lebowski\\] \\[quotes\\] Also, my rug was stolen./";
     $this->assertRegExp($regExp, $strings[3]);
     $regExp = "/ezctest\\S*: \\[Info\\] \\[Lebowski\\] \\[quotes\\] Obviously you're not a golfer./";
     $this->assertRegExp($regExp, $strings[4]);
     $regExp = "/ezctest\\S*: \\[Notice\\] \\[Walter\\] \\[quotes\\] Forget it, Donny, you're out of your element!/";
     $this->assertRegExp($regExp, $strings[5]);
     $regExp = "/ezctest\\S*: \\[Failed audit\\] \\[Walter\\] \\[quotes\\] Donny you're out of your element! Dude, the Chinaman is not the issue here!/";
     $this->assertRegExp($regExp, $strings[6]);
     $regExp = "/ezctest\\S*: \\[Fatal\\] \\[The stranger\\] \\[quotes\\] Ok, Dude. Have it your way./";
     $this->assertRegExp($regExp, $strings[7]);
 }
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:32,代码来源:writer_syslog_test.php

示例9: ExecWaitTimeout

/**
 * Execute a command and kill it if the timeout limit fired to prevent long php execution
 * 
 * @see http://stackoverflow.com/questions/2603912/php-set-timeout-for-script-with-system-call-set-time-limit-not-working
 * 
 * @param string $cmd Command to exec (you should use 2>&1 at the end to pipe all output)
 * @param integer $timeout
 * @return string Returns command output 
 */
function ExecWaitTimeout($cmd, $timeout = 5)
{
    echo $cmd . "\n";
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
    $pipes = array();
    $timeout += time();
    $process = proc_open($cmd, $descriptorspec, $pipes);
    if (!is_resource($process)) {
        throw new Exception("proc_open failed on: " . $cmd);
    }
    $output = '';
    do {
        $timeleft = $timeout - time();
        $read = array($pipes[1]);
        //     if($timeleft > 0)
        stream_select($read, $write = NULL, $exeptions = NULL, $timeleft, NULL);
        if (!empty($read)) {
            $output .= fread($pipes[1], 8192);
        }
    } while (!feof($pipes[1]) && $timeleft > 0);
    if ($timeleft <= 0) {
        proc_terminate($process);
        throw new Exception("command timeout on: " . $cmd);
    } else {
        return $output;
    }
}
开发者ID:larryu,项目名称:magento-b2b,代码行数:36,代码来源:pricematchAllRunner.php

示例10: start

 /**
  * Start the process.
  *
  * After the process is started, the standard IO streams will be constructed
  * and available via public properties. STDIN will be paused upon creation.
  *
  * @param LoopInterface $loop        Loop interface for stream construction
  * @param float         $interval    Interval to periodically monitor process state (seconds)
  * @throws RuntimeException If the process is already running or fails to start
  */
 public function start(LoopInterface $loop, $interval = 0.1)
 {
     if ($this->isRunning()) {
         throw new \RuntimeException('Process is already running');
     }
     $cmd = $this->cmd;
     $fdSpec = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
     // Read exit code through fourth pipe to work around --enable-sigchild
     if ($this->isSigchildEnabled() && $this->enhanceSigchildCompatibility) {
         $fdSpec[] = array('pipe', 'w');
         $cmd = sprintf('(%s) 3>/dev/null; code=$?; echo $code >&3; exit $code', $cmd);
     }
     $this->process = proc_open($cmd, $fdSpec, $this->pipes, $this->cwd, $this->env, $this->options);
     if (!is_resource($this->process)) {
         throw new \RuntimeException('Unable to launch a new process.');
     }
     $this->stdin = new Stream($this->pipes[0], $loop);
     $this->stdin->pause();
     $this->stdout = new Stream($this->pipes[1], $loop);
     $this->stderr = new Stream($this->pipes[2], $loop);
     foreach ($this->pipes as $pipe) {
         stream_set_blocking($pipe, 0);
     }
     $loop->addPeriodicTimer($interval, function (Timer $timer) {
         if (!$this->isRunning()) {
             $this->close();
             $timer->cancel();
             $this->emit('exit', array($this->getExitCode(), $this->getTermSignal()));
         }
     });
 }
开发者ID:shsrain,项目名称:ypyzApi,代码行数:41,代码来源:Process.php

示例11: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     global $pdo_dsn, $db_username, $db_password;
     $dsn = $this->parseDSN($pdo_dsn);
     $dry_run = $input->getOption('dry-run');
     $cmd = 'mysqldump --host=' . escapeshellarg($dsn['host']) . ' --user=' . escapeshellarg($db_username) . ' --password=' . escapeshellarg($db_password) . ' ' . escapeshellarg($dsn['dbname']) . ' ';
     if ($input->getArgument('outputfile')) {
         $file = $input->getArgument('outputfile');
     } else {
         if (!is_dir(REAL_PATH . '/../backups/')) {
             mkdir(REAL_PATH . '/../backups/');
         }
         $file = REAL_PATH . '/../backups/' . strftime('%F-%T.sql');
     }
     $output->writeln("<info>Running: {$cmd}</info>");
     $output->writeln("<info>Output to: {$file}</info>");
     if (!$dry_run) {
         $proc = proc_open($cmd, array(0 => array('pipe', 'r'), 1 => array('file', $file, 'w'), 2 => array('pipe', 'w')), $pipes, null, array());
         $status = proc_get_status($proc);
         while ($status['running']) {
             sleep(1);
             $output->write('.');
             $status = proc_get_status($proc);
         }
         if ($status['exitcode']) {
             $output->writeln('<error>' . stream_get_contents($pipes[2]) . '</error>');
             return $status['exitcode'];
         }
         $output->writeln("\n<info>Done</info>");
     }
 }
开发者ID:cengn-tao,项目名称:racktables-contribs,代码行数:31,代码来源:console.php

示例12: 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;
 }
开发者ID:robertbasic,项目名称:usher,代码行数:33,代码来源:Execute.php

示例13: 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;
 }
开发者ID:barcelonascience,项目名称:libphutil,代码行数:40,代码来源:PhutilExecPassthru.php

示例14: listen

 public function listen($host, $port)
 {
     self::$host_port = $host . ':' . $port;
     // partly borrowed from https://github.com/php/php-src/blob/master/ext/curl/tests/server.inc
     // but make it more simple
     $php_executable = getenv('TEST_PHP_EXECUTABLE');
     $php_executable = $php_executable ?: getenv('_');
     $doc_root = __DIR__ . DIRECTORY_SEPARATOR . 'server';
     $descriptorspec = array(0 => STDIN, 1 => STDOUT, 2 => STDERR);
     echo "start local server\n";
     if (substr(PHP_OS, 0, 3) == 'WIN') {
         $cmd = "{$php_executable} -t {$doc_root} -n -S " . self::$host_port;
         $this->_server = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
     } else {
         $cmd = "exec {$php_executable} -t {$doc_root} -n -S " . self::$host_port;
         $cmd .= " 2>/dev/null";
         $this->_server = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
     }
     if (is_resource($this->_server)) {
         $fp = 0;
         $i = 0;
         while ($i++ < 30 && !($fp = @fsockopen($host, $port))) {
             usleep(10000);
         }
         if ($fp) {
             fclose($fp);
         }
         echo "local server started\n";
     } else {
         echo "start local server failed\n";
         exit;
     }
 }
开发者ID:4honor,项目名称:air,代码行数:33,代码来源:server.inc.php

示例15: call_cfadmin

/**
 * @param $userid int
 * @param $action string
 * @param $data array
 * @throws Exception
 * @returns stdClass
 */
function call_cfadmin($userid, $action, $data = array())
{
    if (!is_int($userid)) {
        throw new Exception('Invalid userid passed to `call_cfadmin`');
    }
    if (!is_string($action) || !$action) {
        throw new Exception('Invalid action passed to `call_cfadmin`');
    }
    if (!is_array($data)) {
        throw new Exception('Invalid data passed to `call_cfadmin`');
    }
    $stdin = "{$userid} {$action} ";
    foreach ($data as $key => $value) {
        $stdin .= "{$key} {$value} ";
    }
    $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
    $process = proc_open("/usr/local/cpanel/bin/cfadmin", $descriptorspec, $pipes);
    if (!is_resource($process)) {
        throw new Exception('Unable to open process to cfadmin');
    }
    // write necessary data to cfadmin for it to run
    fwrite($pipes[0], $stdin . "\n");
    fclose($pipes[0]);
    $response = stream_get_contents($pipes[1]);
    fclose($pipes[1]);
    $return_value = proc_close($process);
    if ($return_value !== 0) {
        throw new Exception('Error code returned from cfadmin');
    }
    // try to parse out the javascript response
    // cfadmin adds a period on its own line to make cpanel happy, so we need to trim that off to get valid json.
    $json_string = trim($response, ". \t\n\r");
    $response_object = json_decode($json_string);
    return $response_object;
}
开发者ID:webhost,项目名称:CloudFlare-CPanel,代码行数:42,代码来源:default-on.php


注:本文中的proc_open函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。