Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write response to browser window

Status
Not open for further replies.

panini

MIS
Jun 1, 2001
136
GB
hi again,

I'm a php newbie - and am having a problem with the code below.

Basically it's timing out or cutting the request off before it gets a response back from the remote server (which can take up to 10 seconds). I'd also like to write the server response to the screen - can anyone point me in the right direction?

The code is:

<?php
$fp = fsockopen ("192.168.1.24",6100,$errno, $errstr);
if (!$fp)
{
print "Unable to Connect";
}
fputs($fp,"-mc6 -tr0 -ds1\"MAIL\" -rfC -x"); //send data
$ready = fgets($fp, 3);

for ($elapsed = 0; $elapsed < 256; $elapsed++)
{
$script_result = 5;
$tcp_response = fgets($fp,1);
$z = strpos($in_data, "-x");
if ($z != 0) // -x found
{
$elapsed = 256;
$in_data = sprintf("%s%s",$in_data,$tcp_response);
fputs($fp,"ACK\n");
}
else
{
$in_data = sprintf("%s%s",$in_data,$tcp_response);
}
}



fclose($fp);

?>
 
I would set in intermediate print statements so that you can better understand how far the script is getting:

Code:
<?php
$fp = fsockopen ("192.168.1.24",6100,$errno, $errstr);
if (!$fp)
{
    print "Unable to Connect";
}
[COLOR=red]print "Supposed connection....sending data";[/color]
fputs($fp,"-mc6 -tr0 -ds1\"MAIL\" -rfC -x"); //send data
[COLOR=red]print "Data sent. getting..."; [/color]
$ready = fgets($fp, 3);
[COLOR=red]print "initiating 256 gets...";[/color]
for ($elapsed = 0; $elapsed < 256; $elapsed++)   
{
    $script_result = 5;
    $tcp_response = fgets($fp,1);
    $z = strpos($in_data, "-x");
    if ($z != 0) // -x found
    {
    $elapsed = 256;
    $in_data = sprintf("%s%s",$in_data,$tcp_response);
    fputs($fp,"ACK\n");
    }
    else
    {
    $in_data = sprintf("%s%s",$in_data,$tcp_response);
        }
}



fclose($fp);

?>


put in oogles of them so that you will know exactly where the script is hanging....

The other thing that I would check is to see if the remote machine is accepting the connection. Not sure I know how you would check that. Depending on the program you have running over there (if its your program, and you have physical access to the machine) make it print something to the screen everytime something connects.



Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

robert (at) robertcarpenter (dot) net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top