Symfony 2.3 で別の MSSQL Server のループを作成しようとしましたが、一部のサーバーがオフになっているか、MSSQL サービスがダウンしている場合、アプリは例外を作成せず、関数を壊します。
これはメインコントローラーです:
function pruebaconAction()
{
$enlistaServers = new array (
10.10.10.1,
10.10.10.2,
10.10.10.3,
...
10.10.10.19,
10.10.10.20
);
foreach($enlistaServers as $datosServer)
{
$direccionIPParaConexion = $datosServer->getDireccionIp ();
$nombreLocalidad = $datosServer->getNombre();
register_shutdown_function(array($this, 'conectaSrv'), $direccionIPParaConexion, $nombreLocalidad);
}
return $this->render("GastoEnlaceBundle:Default:pruebacon.html.twig");
}
この関数は接続を作成します:
function conectaSrv($direccionIpConexion, $nombreLocalidad)
{
$pruebaDBAL = new \Doctrine\DBAL\Configuration();
$parametrosConexion = array(
'dbname' => 'MyDB',
'user' => 'user',
'password' => 'password',
'host' => $direccionIpConexion,
'driver' => 'pdo_sqlsrv'
);
$conexionDBAL = DriverManager::getConnection($parametrosConexion, $pruebaDBAL);
if($conexionDBAL->connect())
echo "Success<br />";
else
throw new Exception("Something is wrong :(<br />");
echo "=======================================================================<br />";
}
オンラインのすべてのサーバーで常に同じ結果が得られますが、接続は成功していますが、一部のサーバーがオフラインの場合、関数は例外を送信せず、ループを中断します。
誰かが私を助けたりアドバイスをくれたりしてくれることを願っています。どうもありがとう。