I am trying to make a simple TCP/IP connection to a given IP and Port using sockets in PHP.
I am getting an error message that says "A non-blocking socket operation could not be completed immediately." below is my code:
<?php
$address = 'myhost.com';
$service_port = 1234;
$timeout = 1000;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_nonblock($socket);
$error = NULL;
$attempts = 0;
while (!($connected = @socket_connect($socket, $address, $service_port)) && ($attempts < $timeout)) {
$error = socket_last_error();
if ($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY) {
echo socket_strerror($error) . "\n";
socket_close($socket);
return NULL;
}
usleep(1000);
$attempts++;
}
?>
any ideas? i know there are no issues with the target host ip or port.