Re: Need direction on PHP-CLI MUD Server
| From: | Jim Grill | Date: | Thu, 02 Sep 2004 14:31:13 +0000 |
| Subject: | Re: Need direction on PHP-CLI MUD Server | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-195574@lists.php.net to get a copy of this message | ||
> Hello, I have been banging my head trying to figure out how to design a
MUD
> Server using PHP-CLI as the server and PHP-CLI as the "command" language.
> (telnet front end at this point)
>
> but....
>
> The real problem is full interaction with the user in those external
> commands (php-cli scripts) to send and read data.
>
>
> A. How do I create a input method to connect the external PHP script to
the
> Server's Socket?
>
> B. Since the PHP-CLI script never ends how can I send the first echo "You
> have..."?
> D Myers
>
I hope I'm understanding what you're asking. If you need to interact with
the user via stdin you can use this function to capture user input:
function read()
{
$fp=fopen("/dev/stdin", "r");
$input=fgets($fp, 255);
fclose($fp);
return $input;
}
Your code flow could look something like:
<?php
do {
print "what's your name?\n";
$name = read();
} while (empty($name));
print "Hello $name!\n";
sleep(1);
do {
print "What is your jedi name?\n";
$jediName = read();
} while (empty($jediName));
print "Hello $name AKA $jediName\n\n";
function read()
{
$fp=fopen("/dev/stdin", "r");
$input=fgets($fp, 255);
fclose($fp);
return trim($input);
}
?>
I hope that gets you started in the right direction. Sounds like a fun
project.
Jim Grill
Web-1 Hosting, LP
http://www.web-1hosting.net