在API Endpoint仍在运行时将反馈返回给它

时间:2017-10-19 00:27:59

标签: php laravel api curl endpoint

我有一个简单的API

http://site/api/script/start?account=5000

它只是一个在我的数据库中创建5000个帐户的脚本。

当我点击该API时,此代码运行

$add = 0; 

for ($i = 0; $i < $account_total; $i++) {

    $max_id = 0;
    $account_id = $max_id+1;
    $url = env('API_HOST').'vse/account';

    $json = '{"account_id":'.$account_id.',"email_address":"'.$type.$account_id.'@benu.com","password":"benu123","account_type":"customer","name_prefix":"","first_name":"'.strtoupper($type).'","middle_names":"","last_name":"'.$account_id.'","name_suffix":"","non_person_name":false,"DBA":"","display_name":"","address1":"","address2":"","address3":"","city":"Boston","state":"MA","postal_code":"02115","nation_code":"USA","phone1":"723487432","phone2":"","phone3":"","time_zone_offset_from_utc":-5,"customer_type":"'.$customer_type.'","longitude":0,"latitude":0,"altitude":0}';
    CURL::post($url,$json);

    echo $add++;
}

代码运行良好。这些帐户已添加,但我对它进行了GET

NO反馈,就好像正在添加帐户一样。

看起来很简单。

enter image description here

我想知道

如果有一种方法可以在添加帐户时返回帐户的增量。

我尝试添加echo $add++;

它似乎不起作用。

如何实现并实现这样的目标?

1 个答案:

答案 0 :(得分:1)

尝试

flush();

之后

echo $add++;

http://php.net/manual/en/function.flush.php