Model.request_async - kouji6309/SingleMVC GitHub Wiki
建立一個即將對指定網址請求的資源,但不執行請求。通常接續使用 Model::request_run。
protected static request_async(
string $url,
string $method = 'get',
mixed $data = [],
array $option = []
) : CurlHandle
-
請求路徑。
此數值將會設定CURLOPT_URL
。 -
請求方法,一般使用
GET
、POST
、PUT
、DELETE
、OPTIONS
。
此數值將會設定CURLOPT_CUSTOMREQUEST
。 -
輸入資料,會根據
method
與option['Header']['Content-Type']
不同而有所處理。 -
設定選項,相同於 Model::request。
- 布林:
false
,執行失敗。 - cURL 資源的控制代碼。
建立多個請求,之後同步執行請求
$chs = [];
for ($i = 1; $i <= 10; $i++) {
$chs[] = self::request_async(
'https://www.example.com/api/news',
'get', ['id' => $i]
);
}
$result = self::request_run($chs);