Page 1 of 1

using telnet inside php code

Posted: Tue Jun 28, 2005 1:18 pm
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

Posted: Tue Jun 28, 2005 2:04 pm
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
}

Posted: Tue Jun 28, 2005 2:21 pm
by srirams
If the site is down the browser throws an error message in 30.

Instead can we just display
site is down.

Posted: Tue Jun 28, 2005 2:34 pm
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
}

Posted: Tue Jun 28, 2005 2:35 pm
by timvw
http://www.php.net/fsockopen

The answer is there :P