1
我有一個服務,正在調用一個REST服務器。我正在使用CURL來提出請求。我們有三個端點用於分配負載。我可以創建一些基本邏輯,可以「隨機」選擇一個終點,但這看起來不像是一個「好」的解決方案。我想知道是否有更好的解決方案?PHP curl_init負載平衡多個服務器
define ("REST_SERVER", "http://myService.myCompany.com:8280");
...
$url = REST_SERVER.URL_SIGN;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$curl_result = curl_exec($ch);
在您的服務器上使用* actual *負載平衡器? – slugonamission
我會說你的「客戶」代碼(=使用REST API的代碼)不應該做負載平衡,你的端點應該這樣做......如果你不想這樣做,那麼你的想法不是這樣壞 –