using telnet inside php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

using telnet inside php code

Post by srirams »

Hi,

Can anyone tell me how to use telnet command inside php.
I tried this
$output = shell_exec('telnet loneqresdbu2.uk.db.com 9001');
echo $output;

But it is not outputting anything.
and also how do I close the telnet connection.

Regards
Sriram.S
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

$fp = fsockopen('loneqresdbu2.uk.db.com', 9001);

// probably need to login
fwrite($fp, "username\n");
fwrite($fp, "password\n");

while ($line = fread($fp, 2048))
{
  // do things with $line
}
srirams
Forum Commoner
Posts: 36
Joined: Wed May 25, 2005 8:57 am
Location: India
Contact:

Post by srirams »

If the site is down the browser throws an error message in 30.

Instead can we just display
site is down.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

srirams wrote:If the site is down the browser throws an error message in 30.

Instead can we just display
site is down.

Code: Select all

$fp = @fsockopen('loneqresdbu2.uk.db.com', 9001);

if ($fp) { 
    // probably need to login
    fwrite($fp, "username\n");
    fwrite($fp, "password\n");
 
    while ($line = fread($fp, 2048))
    {
       // do things with $line
    }
} else {
    //return error
}
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

http://www.php.net/fsockopen

The answer is there :P
Post Reply