Skip to content

Instantly share code, notes, and snippets.

@xendk
Created February 23, 2015 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xendk/1d5398a18fdc28f8deb2 to your computer and use it in GitHub Desktop.
Save xendk/1d5398a18fdc28f8deb2 to your computer and use it in GitHub Desktop.
Challenge
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Process\ProcessBuilder;
// This doesn't work. The stream_select inside Process doesn't see any new
// input. We want to create a stream that can be written to asyncroniouly.
$inputStream = fopen("php://temp/", 'r+');
$processBuilder = new ProcessBuilder(array('cat'));
$processBuilder->setInput($inputStream);
$process = $processBuilder->getProcess();
$process->start();
// Doesn't have to be fwrite.
fwrite($inputStream, "We have a winner!\n\n");
fclose($inputStream);
$exitCode = $process->wait();
$output = $process->getOutput();
if (empty($output)) {
echo "Sorry, no dice.\n\n";
} else {
echo $output;
}
{
"require": {
"php": ">=5.4.0",
"symfony/process": "~2.0"
}
}
@gielfeldt
Copy link

It doesn't looke like Process and/or UnixPipes support proc_open() with a file resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment