PHP code example of takuya / process

1. Go to this page and download the library: Download takuya/process library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

takuya / process example snippets




$proc1 = new Process('sh');

$fd_out = $proc1->setInput('echo HelloWorld')
  ->pipe('cat')
  ->pipe('cat')
  ->pipe(['grep', 'Hello'])
  ->wait();

$ret = stream_get_contents($fd_out);




$proc = new Process(['echo', 'HelloWorld']);
$fd_out = $proc->run();

$output = stream_get_contents($fd_out);
// you can reuse, re-read output  
fseek($fd_out,0);
$str = stream_get_contents($fd_out);


$proc = new Process('sh sleep.sh');
$proc->start();
echo 'started';
$proc->join();



$proc = new Process(['echo', 'HelloWorld']);
$fd_out =  $proc->pipe('cat')
            ->pipe('cat')
            ->pipe('cat')
            ->pipe('cat')
            ->wait();


$proc1 = new Process(['echo', 'HelloWorld']);
$proc2 = new Process(['cat']);
[$p1_out,$p1_err] = $proc1->start();
$proc2->setInput($p1_out);
$proc2->start();
$proc2->wait();
$proc1->wait();