note 56217 deleted from function.readline by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 12:39:02 +0000 |
| Subject: | note 56217 deleted from function.readline by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189689@lists.php.net to get a copy of this message | ||
Note Submitter: Vylen
----
I've got another solution for those those without readline compiled on a linux system.
This one is different as it is specifically for different PHP files opened by proc_open or in the
CLI and are constantly looking for input.
<?php
// Define the pointer
$readline = popen("while true; do { read reply; echo \$reply ; }; done", "r");
// Some class
class example {
function data() {
global $readline;
// Return any data from $readline, substr() is to remove the trailing linebreak, its really
optional.
return(substr(fgets($readline, 1024), 0, -1));
}
}
$example = new example();
while($line = $example->data()) {
if($line == 'hello')
echo "Hi to you too!\n";
else
echo "recieved input\n";
}
?>