RE: How to check port conection? socket_connect and fso ckopen have problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Why do you need to call a socket 1000 times in order
to find out if a service is available or not? 


-----Original Message-----
From: Sherry
To: php-windows@xxxxxxxxxxxxx
Sent: 8-5-2004 17:03
Subject:  How to check port conection? socket_connect and fsockopen
have problems

Hi, I have Apache 1.3.29+PHP 4.3.6 on WinXP.
I need to check some services (ftp, http, smtp) on other machines for
availability.

--- Method 1 ---
So I try to use fsockopen:

$handle = fsockopen($ip, $port, $errno, $errstr, 5);
if ($handle)    {    close($handle); $online=1;    }    else    {
$online=0;    }

Everything looks fine, but there is one problem. Apache open 2 kind of
connections when I call fsockopen.
It looks in TCPView like:
apache.exe    src_host:src_port    host:0
LISTENING
apache.exe    src_host:src_port    dest_host:dest_port   SYN_SENT

When 5 seconds timeout occurs, apache closes second connection, but
leave
first connection alive!
So, if I try to call fsockopen 1000 times, I got 1000 connections from
apache in LISTENING state!

Is there any ways to solve this problem?

--- Method 2 ---
When I try to use socket_connect, there is other problem appear.

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$exist = socket_connect($socket, $host, $port);
if ($exist)    {    socket_shutdown($socket);    socket_close($socket);
$online=1;    }    else    {    $online=0;    }

Socket_close works normally, but it leaves connection in TIME_WAIT
state.
This connections closes automaticaly when time_wait timeout occurs, but
this
timeout is very large! How I can make it smaller?

--- Method 3, etc? ---
Or may be there exist some other ways to check port and services for
availability???

With best regards,
Sherry.

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux