Using a file that stores an array of connection data with their respective ID(s), I want to start a socket connection. However, if the default connection fails, I want there to be a loop that adds one to the most recent connection's ID, and then attempts to reconnect. Only problem is that I am stumped as to how I would do the looping.
This is the file that stores the connection information (servers.php):
Code: Select all
<?php
/* Connection data */
$servers = array (
100 = array (
'server_ip' => '192.168.0.12',
'server_port' => 7100
),
101 = array (
'server_ip' => '192.168.0.12',
'server_port' => 7101
)
);
?>Code: Select all
<?php
require("servers.php");
require("config.php");
if(!defined(SHUTDOWN)) {
set_time_limit(0);
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
$bind = socket_bind($sock, $server[100]['server_ip'], $server[100]['server_port']);
if(!$bind) {
//The loop should go here
}
socket_listen($sock);
//Everything else
}
elseif(defined(SHUTDOWN)) {
//things to do if the server is offline
}
?>Code: Select all
for($i=100; $i<=101; $i++) {
//connect here using $servers[$i]['server_ip'] and then the port
}