PHP cURL基于数据库中id的多次调用

时间:2017-04-14 12:34:32

标签: php json curl

我正在尝试根据不同的ID自动执行150 cURLS请求。每个cURL都以JSON格式生成输出。我在mysql数据库中有这些id。

我认为有以下步骤:

1。)从数据库获取id

2。)构造,根据id为每个cURL加载en save输出。 (www.domain.com//string)

3。)对每个id重复步骤2。

我在这个领域没有太多经验,所以我的问题是从哪里开始?

1 个答案:

答案 0 :(得分:0)

是的,那是正确的流程。让我给你一些我认为会起作用的代码。好的,首先,我们假设我们有类DB(我通常使用meekrodb);

$dataId = DB::queryOneColumn('id', "SELECT * FROM your_table_data ORDER by some_column LIMIT 150");
DB::startTransaction();
foreach($dataId as $id){
    $response = requestWithCurl($id);
    DB::insert('your_table', array('json_column' => $response));
}
DB::commit();

以下是执行cUrl的功能,请参阅php curl example

function requestWithCurl($id){
    # initiate curl
    # define host/url
    # execute curl with data that contain $id
    # return curl response, we assume that response already in json formatted
}

希望这有效。 :))