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

  • Home
  • SEARCH
  • 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 3242302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:17:57+00:00 2026-05-17T18:17:57+00:00

ive ran into an issue while creating a PHP telnet script at work to

  • 0

ive ran into an issue while creating a PHP telnet script at work to gather network data.

as the amount of data returned from the ‘Action: Status’ command could be of any size… im concerned about using a static number with fread() on line 13. I have also tried using fgets() instead but it only grabs the first line of data (the META HTTP line… without the table). how can I grab an arbitrary amount of data from the socket using PHP? please help

<?php
$ami = fsockopen("192.100.100.180", 5038, $errno, $errstr);

if (!$ami) {
echo "ERROR: $errno - $errstr<br />\n";
} else {

    fwrite($ami, "Action: Login\r\nUsername: 1005\r\nSecret: password\r\nEvents: off\r\n\r\n");

    fwrite($ami, "Action: Status\r\n\r\n");
    sleep(1);

    $record = fread($ami,9999);#this line could over run!!!
    $record = explode("\r\n", $record);
    echo "<META HTTP-EQUIV=Refresh CONTENT=\"9\">"; #refresh page every 9 seconds
    echo "<table  border=\"1\">";


    foreach($record as $value){
        if(!strlen(stristr($value,'Asterisk'))>0
        && !strlen(stristr($value,'Response'))>0
        && !strlen(stristr($value,'Message'))>0
        && !strlen(stristr($value,'Event'))>0
        && strlen(strpos($value,' '))>0) #remove blank lines
        php_table($value);;
    }

    echo "</table>";

    fclose($ami);
    }


function php_table($value){
        $row1 = true;
        $value = explode(" ", $value);
        foreach($value as $field){
            if($row1){
                echo "<tr><td>".$field."</td>";
                $row1 = false;
            }
            else{
                echo "<td>".$field."</td></tr>";
                $row1 = true;
            }
        }
}

?>
  • 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-17T18:17:58+00:00Added an answer on May 17, 2026 at 6:17 pm
    while (strlen($c = fread($fp, 1024)) > 0) {
        $record .= $c;
    }
    

    Edit: Your application hangs because it’s not closing the connection to signify the end of a HTTP request. Try

    fwrite($ami, "Action: Status\r\n\r\n"); 
    fwrite($ami, "Connection: Close\r\n\r\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing a game for J2ME we ran into an issue using java.lang.Integer.parseInt() We
I've ran into a problem while trying to test following IRepository based on NHibernate:
Ran into a strange problem in PHP today and I'm wondering if someone can
Our current project has ran into a circular dependency issue. Our business logic assembly
I've just started with opengl but I ran into some strange behaviour. Below I
I've been working on optimizing a query and have ran into a situation that's
I've actually solved this, but I'm posting it for posterity. I ran into a
I've installed Ubuntu Server (8.04) into Parallels and found that the system time/clock ran
Ive been smashing my head with this for a while. I have 2 completely
I ran into the problem that two drives connected at nearly the same time

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.