예제 #1
0
<?php

use Amp\Process;
include __DIR__ . "/../vendor/autoload.php";
\Amp\run(function () {
    $proc = new Process('read ; echo "$REPLY"');
    $promise = $proc->exec(Process::BUFFER_ALL);
    /* send to stdin */
    $proc->write("abc\n");
    /* wait for process end */
    $result = (yield $promise);
    var_dump($result->stdout);
    // "abc"
});
예제 #2
0
 /**
  * @param array  $certificate certificate configuration
  * @param string $server server to use for issuance
  * @param string $storage storage directory
  * @return \Generator
  * @throws AcmeException if something does wrong
  */
 private function checkAndIssue(array $certificate, $server, $storage)
 {
     $domainPathMap = $this->toDomainPathMap($certificate["paths"]);
     $domains = array_keys($domainPathMap);
     $commonName = reset($domains);
     $args = [PHP_BINARY, $GLOBALS["argv"][0], "check", "--server", $server, "--storage", $storage, "--name", $commonName, "--names", implode(",", $domains)];
     $command = implode(" ", array_map("escapeshellarg", $args));
     $process = new Process($command);
     $result = (yield $process->exec(Process::BUFFER_ALL));
     if ($result->exit === 0) {
         // No need for renewal
         (yield new CoroutineResult(self::STATUS_NO_CHANGE));
         return;
     }
     if ($result->exit === 1) {
         // Renew certificate
         $args = [PHP_BINARY, $GLOBALS["argv"][0], "issue", "--server", $server, "--storage", $storage, "--domains", implode(",", $domains), "--path", implode(PATH_SEPARATOR, array_values($domainPathMap))];
         if (isset($certificate["user"])) {
             $args[] = "--user";
             $args[] = $certificate["user"];
         }
         if (isset($certificate["bits"])) {
             $args[] = "--bits";
             $args[] = $certificate["bits"];
         }
         $command = implode(" ", array_map("escapeshellarg", $args));
         $process = new Process($command);
         $result = (yield $process->exec(Process::BUFFER_ALL));
         if ($result->exit !== 0) {
             throw new AcmeException("Unexpected exit code ({$result->exit}) for '{$command}'." . PHP_EOL . $result->stdout . PHP_EOL . PHP_EOL . $result->stderr);
         }
         (yield new CoroutineResult(self::STATUS_RENEWED));
         return;
     }
     throw new AcmeException("Unexpected exit code ({$result->exit}) for '{$command}'." . PHP_EOL . $result->stdout . PHP_EOL . PHP_EOL . $result->stderr);
 }
예제 #3
0
<?php

use Amp\Process;
include __DIR__ . "/../vendor/autoload.php";
\Amp\run(function () {
    $proc = new Process("echo 1");
    $result = (yield $proc->exec(Process::BUFFER_ALL));
    var_dump($result->stdout);
    // "1"
});
예제 #4
0
<?php

use Amp\Process;
include __DIR__ . "/../vendor/autoload.php";
\Amp\run(function () {
    $proc = new Process("echo 1; sleep 1; echo 2; sleep 1; echo 3");
    $promise = $proc->exec();
    $promise->watch(function ($data) {
        // $data[0] is either "out" or "err", $data[1] the actual data
        list($type, $msg) = $data;
        // "1" ... 2 seconds ... "2" ... 2 seconds ... "3"
        print "{$type}: {$msg}";
    });
    $result = (yield $promise);
    // we aren't buffering by default (Process::BUFFER_NONE is default) ... so only exit code present and eventually the killing signal
    var_dump($result);
});
예제 #5
0
 public function testOptions()
 {
     $process = new Process(self::CMD_PROCESS);
     $this->assertSame([], $process->options());
 }
예제 #6
0
 public function testGetCommand()
 {
     $process = new Process(self::CMD_PROCESS);
     $this->assertSame(self::CMD_PROCESS, $process->getCommand());
 }