Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP function fsockopen never returning false

Tags:

php

fsockopen

Could somebody help me with the php function fsockopen?

if I call the function like this :

$fp = fsockopen('xywqnda.com', 80, $errno, $errstr, 10);

With an unavailable host domain, it will never return false and I don't understand why!

like image 246
Arba Constantin-Andrei Avatar asked Nov 25 '25 02:11

Arba Constantin-Andrei


1 Answers

Ah, you are using UDP. Your original example didn't show this. This changes things. From the PHP manual:

Warning

UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data.

like image 146
Sarke Avatar answered Nov 26 '25 16:11

Sarke