Skip to content

Instantly share code, notes, and snippets.

@sbisbee
Created June 3, 2012 22:28
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 sbisbee/2865231 to your computer and use it in GitHub Desktop.
Save sbisbee/2865231 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# foo.plx
# This is what the other file sends its contents to.
open(FILE, ">/tmp/foo");
print FILE "----start----\n";
# Write all of the piped input to the FILE
while(<STDIN>) {
print FILE $_;
}
print FILE "----end----";
close(FILE);
<?php
// Create the process, naming the in/out pipes.
$proc = proc_open(
'/home/sbisbee/src/foo.plx',
array( array('pipe', 'r'), array('pipe', 'w') ),
$pipes
);
if(is_resource($proc)) {
// Get this file's contents ($_SERVER['SCRIPT_FILENAME']) and write them
fwrite($pipes[0], file_get_contents($_SERVER['SCRIPT_FILENAME']));
fclose($pipes[0]);
// See what the script returns to us (if anything)
echo '<div>' . stream_get_contents($pipes[1]) . '</div>';
// Always make sure you clean up your procs before terminating.
fclose($pipes[1]);
echo 'command returned ' . proc_close($proc);
}
else {
echo 'could not open the process';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment