I have a problem of waiting socket_recvfrom to receive something otherwise the script won't continue running
for( $i= 1024 ; $i <= 65535 ; $i++ ) {
$sock[$i] = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($sock[$i], $sourceips['madcoder'],$i);
socket_connect($sock[$i], '115.188.58.144 ', 1195);
$request = 'data';
socket_write($sock[$i], $request);
$from = '';
$port = 0;
$valeur = socket_recvfrom($sock[$i], $buf, 1222, 0, $from, $port);
}
this code basically send a udp request on a different local port each time and see if he got a response The pogramme now is stuck waiting to receive a packet thanks to socket_recvfrom
I want to make it run as fast as i could without risking to lose a response
i could use
socket_set_option($sock[$i], SOL_SOCKET, SO_RCVTIMEO, array('sec' => 1, 'usec' => 0));
but the problem is waiting for over a 1 second is too much and there is a problem with setting a value of under a second
changing the value to
array('sec' => 0, 'usec' => 100)
or
array('sec' => 0.1, 'usec' => 0)
won't work so i was thinking of multi threading ,The only way i know to multi thread is a "for" loop like i did but i really wish if i could try something else more effective