25
Aug
Talking to command line apps with php
By Joseph Montanez
0 Comment

Php has a ton of built-in features but there is always times where shit hit the fan and you need to hack you way around the server to use its built cli apps to better serve you. There are a few builtin functions with php to execute these programs. But when you need to keep a process open and continue to pipe data to it, then it gets complicated. So I've build a very simple library to handle this easy and with safely (leaving pipes open could kill ur server's cpu)

File: Gorilla3D Zip 1Kb

Simple Example

require_once 'Gorilla3D/Process.php';
// Setup the process
$proc = new Gorilla3D_Process('ls -l');
$proc->open();
// read the response;
$proc->read($output);
echo '<pre>', $output, '</pre>';
/*
total 28
-rw-r--r-- 1 xxx3d xxx3d  215 Aug 25 04:35 atm.php
-rw-r--r-- 1 xxx3d xxx3d 2917 Aug 25 05:52 index.php        
 */
$proc->close();

Complex Example

require_once 'Gorilla3D/Process.php';
// Setup the process
$proc = new Gorilla3D_Process('php atm.php');
$proc->open();

// Write and then read the response line;
$proc->write('30 120')->readLine($output);
echo $output; // 99.50

// Write another and then read the next response line;
$proc->write('40 120')->readLine($output);
echo $output; // 89.50

// Close the process
$proc->close();

« Back to my notebook
Next Note > < Previous Note
Comment Pages: 1


esign