Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Webサービスと相互作用する関数を構築しています。
Webサービスからの応答がない場合は、一時的な不具合の場合に備えて、失敗を登録する前に2、3回再試行したいと思います。
PHPを使用して、これを行うための最良の手法は何でしょうか?
$i = 0; do { $response = getResponseFromWebService(); if ($i++ >= 3) { throw new Exception('Web service unavailable'); } } while (!$response);
おそらく、1回目でうまくいかなければ、2回目、3回目もうまくいかないでしょう。非常に気まぐれな Web サービスを使用している場合を除きます。その場合は、おそらく別の Web サービスを探す必要があります。