PHP socket

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I need to check if a user has properly open his port on his computer. He  
will call a script specifing the port he want to use and the script will  
have to check if he can open a socket on the IP:Port.
Here is a what I have tried but it doesn't work, even if the port is  
properly open :

-----------------------------Script ------------------

if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0)
   die("socket_create() failed : " . socket_strerror($sock) . "\n");

if (($ret = socket_connect($sock, $address, $port)) < 0)
   die("socket_connect() failed : raison : " . socket_strerror ($ret) .  

echo "connected\n";

-------------------------End Script ---------------------

Any suggestions ? Thanks in advance.


Re: PHP socket

Quoted text here. Click to load it

What doesn't work? What does your browser display? What are the error
messages? What OS is your server running? What version? What version of
PHP are you using? So many questions, so little time...


Re: PHP socket

On Mon, 3 Oct 2005 23:08:23 +0200, Boniface Frederic wrote:

Quoted text here. Click to load it

I've been messing with just this lately - see the thread "Ping+Port
Routine". It's not that old.

In short, it's a nightmare!

1) Depends on which build of PHP - whether it was compiled with socket

2) OS Dependent. Many socket functions don't appear to work on a Win32

3) Contrary to what it says on the PHP bugtracker, I think many of the
socket routines still have bugs. Some even appear to have been
re-introduced in PHP5.

4) Check whether a firewall is blocking things.

5) Set up a port "sniffer" (Ethereal or suchlike) to see whether
packets are a actually leaving/arriving (though a firewall can still
block these).

6) I found that a socket sometimes gets "blocked" with an error - even
when the [code] error has been fixed. Try it with another port (that
you know is open). After a time, I've found I can re-use the original
connection. There must be a timeout somewhere.


Site Timeline