PHP Classes

File: examples/example.input.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Asynchronous Command   examples/example.input.php   Download  
File: examples/example.input.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Asynchronous Command
Get commands output without waiting to finish
Author: By
Last change:
Date: 7 years ago
Size: 987 bytes
 

Contents

Class file image Download
<?php
   
/***
        This example runs the askforinput.php script, which prompts the user for some input
        and displays the results.
     ***/
   
require ( '../AsynchronousCommand.php') ;

   
// Execute the askforinput.php script. Note that the second parameter of the AsynchronousCommand
    // constructor is set to true, meaning that we want to write to the process' standard input.
   
$cmd = new AsynchronousCommand ( "php askforinput.php", true ) ;
   
$cmd -> Run ( ) ;

   
// A difficulty I could not overcome is that stream_select() on windows platforms is blocking if
    // some input is requested meanwhile.
    // For that reason, we won't be able to catch the "Please enter something : " prompt until we
    // satisfy the external command input request
   
if ( $cmd -> IsStdinRequested ( ) )
       
$cmd -> WriteLine ( "This is some text piped into askforinput.php standard input" ) ;

   
// Write command output
   
while ( ( $line = $cmd -> ReadLine ( ) ) !== false )
        echo (
$line ) ;