Ok so i have a class that uses while(true)
and it connects using a socket. Now my problem is that when i use socket_set_nonblock it doesn't connect it dies with "Could not connect.". When i put it after sending a packet, it goes from the start and re does everything.
Here is my connect function:
function connect($ip, $port) {
if($this->soc!=null) socket_close($this->soc);
$this->soc = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
if(!$this->soc) die(socket_strerror(socket_last_error($this->soc)));
if(!socket_connect($this->soc,$ip,$port)) die("Could not connect.");
}
Heres the function when attempting to use socket_set_nonblock
function connect($ip, $port) {
if($this->soc!=null) socket_close($this->soc);
$this->soc = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_set_nonblock($this->soc);
if(!$this->soc) die(socket_strerror(socket_last_error($this->soc)));
if(!socket_connect($this->soc,$ip,$port)) die("Could not connect.");
}