i'm creating TCP socket with socket_create php function. But i meet problems with the socket_set_option.
Every documentation I see is really hard to understand, I just want easy example, they are all difficult. This function is like this :
socket_set_option($socket, int $level, int $optname, $opt_val)
But I don't understand any of these parameters
I tried this :
$tcp_timeout=10000;
socket_set_option($sock, SOL_TCP, $tcp_timeout,1);
But I still meet errors (without explanations) Can someone give me a concrete exemple (and no blabla) of how we use this, and how it works?
Here is my initial code :
<?php
$tcp_timeout=10000;
$address="127.0.0.1";
$port="5027";
$msg="\x00\x0f\x33\x35\x31\x35\x38\x30\x30\x35\x31\x30\x38\x32\x31\x31\x39";
$sock=socket_create(AF_INET,SOCK_STREAM,0) or die("Cannot create a socket");
socket_set_option($sock, SOL_TCP, $tcp_timeout,1);
socket_connect($sock,$address,$port) or die("Could not connect to the socket");
socket_write($sock,$msg);
$read=socket_read($sock,1); //Lecture d'un seul byte.
if ($read == "\x01") {
echo "Accepted <br /><br />";
} else {
echo "Error";
}