Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:26:36+00:00 2026-05-22T17:26:36+00:00

How to disconnect from a telnet session using PHP ?Using this below code i

  • 0

How to disconnect from a telnet session using PHP ?Using this below code i read the telnet output.But i want to disconnect from telnet session if data can’t receive in $output variable within 3 second. How i do that.Please see my code below:

$fp = fsockopen("localhost", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    $output=fread($fp,128);//Here we read the output value from socket        
    fclose($fp);                
    echo $output;               
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:26:37+00:00Added an answer on May 22, 2026 at 5:26 pm

    Are you running under linux or Windows? In Linux you could fork the application to run the telnet session in parallel and have the main thread terminate the session after a given time if no output is received.

    In Windows you could probably do a loop that does an fread() on the socket and keep track of time spent without getting any data and closing the socket after a given time.

    Edit:
    I just remembered that you don’t have to keep track of this manually 🙂
    You could probably do something like

    // Set socket timeout to 10 seconds
    socket_set_timeout($fp, 10)
    
    ...
    
     $output=fread($fp,128);//Here we read the output value from socket  
    if($output == false) {
      // Code to run if timeout occured
      echo "We timed out!";
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's possible using eclipse debug perspective to disconnect from a debug process. After this,
Can't see why this is happening, but when I use Bluetooth to send data
have not tested on windows. but in ubuntu when u disconnect from the network,
It seems that whenever I disconnect from clojure slime session, I cannot reconnect again.
i am trying to disconnect a client from a server but the server still
Not sure if this question belongs on SO but ... Can I play Desktop
So I have some session checking to see if it's not stolen using PHP.
Can I force user to disconnect from the app? i.e. if user broke some
I have a Video Chat application that I want to disconnect from a call
I'm using MySQLdb to upload a lot of data from text files into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.