Skip to content

Instantly share code, notes, and snippets.

@xendk

xendk/challenge.php

Created Feb 23, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@gielfeldt gielfeldt commented Feb 24, 2015

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