I need to implement a php script on my website that would do the following:
Everything is already configurated on the server side to respond to packet requests, I only need to figure out how to use php to connect to TCP/IP server.
Any ideas in which direction to look?
The TCP session is sending packets as fast as possible, so when the client sends the FIN and closes its part, the server is still sending lots of data for a moment. In this case, the client sends RST packets until the server stops sending data.
The figure above also shows how a TCP connection is closed (also called cleared or terminated). Either end can initiate a close operation, and simultaneous closes are also supported but are rare. Traditionally, it was most common for the client to initiate a close.
Any HTTP client, server, or proxy can close a TCP transport connection at any time.
You could check if the socket is still connected by trying to write to the file descriptor for each socket. Then if the return value of the write is -1 or if errno = EPIPE, you know that socket has been closed.
Easily with php sockets:
<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
fwrite($fp, "Your message");
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
To read more, go to http://php.net/manual/en/function.fsockopen.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With