|
Posted by yawnmoth on 05/31/07 01:53
For learning purposes, I'd like to create a PHP script that'll output
the system time every minute and, at the same time, will process
"command line" commands as I type them into STDIN. eg.
If I wait a minute, it should output the time. If, ten seconds later,
I type in "dir", it should display the directory information.
Unfortunately, it doesn't do that.
Here's my code:
<?php
$stdin = fopen('php://stdin', 'r');
stream_set_blocking($stdin, 0);
$data = '';
$last_date = '';
while (true)
{
$data.= fgets($stdin, 1024);
if ($data{strlen($data)-1} == "\r" || $data{strlen($data)-1} == "\n")
{
system(trim($data));
$data = '';
}
if ($last_date != date('g:ia'))
{
$last_date = date('g:ia');
echo "\r\nThe time is now [$last_date]\r\n";
}
}
?>
Any ideas?
Navigation:
[Reply to this message]
|