Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect connection abort on a socket opened by fsockopen()

Tags:

php

tcp

sockets

I am using fsockopen() to send data via TCP to a remote host:

$s = fsockopen($host, $port);
fwrite($s, $data);
fclose($s);

How can I detect afterwards if the connection was closed (with a FIN) or aborted (with a RST) by the remote host?

like image 304
AndreKR Avatar asked Nov 13 '22 08:11

AndreKR


1 Answers

According to the documentation socket_last_error() and socket_send() can be helpful for you:

socket_send() returns the number of bytes sent, or FALSE on error. 
socket_last_error() returns the last error on the socket  

I believe, that PHP is able to detect if the connection was closed, however not sure about this.

like image 116
lisachenko Avatar answered Nov 16 '22 03:11

lisachenko