dongzong3053 2019-08-08 21:29
浏览 135

如果第一次尝试成功,为什么这个循环会运行多次?

I also tried putting the break right outside and after the try/catch with a continue inside the catch but no luck. It appears no other exceptions get thrown other than the one there.

do {
    try {
        $result = CM::campaigns()->create(config('campaignmonitor.client_id'), array_merge($optional_params, [
            'Subject' => $campaign->subject,
            'Name' => $campaign->client_id . ' - ' . $campaign->name . ' (' . $campaign->id . ')',
            'FromName' => $campaign->from_name,
            'FromEmail' => $campaign->from_email,
            'ReplyTo' => (!is_null($campaign->reply_email) ? $campaign->reply_email : $campaign->from_email),
            'HtmlUrl' => config('campaignmonitor.emailTemplatePath') . '/' . $campaign->html_file,
            'SegmentIDs' => [$campaign->segment_id]
        ]));

        break;
    } catch (CurlException $e) {
        // Try again
        $cmCreationTries++;
    }
} while ($cmCreationTries < 3);

The following does work as expected though:

do {
    try {
        $result = CM::campaigns()->create(config('campaignmonitor.client_id'), array_merge($optional_params, [
            'Subject' => $campaign->subject,
            'Name' => $campaign->client_id . ' - ' . $campaign->name . ' (' . $campaign->id . ')',
            'FromName' => $campaign->from_name,
            'FromEmail' => $campaign->from_email,
            'ReplyTo' => (!is_null($campaign->reply_email) ? $campaign->reply_email : $campaign->from_email),
            'HtmlUrl' => config('campaignmonitor.emailTemplatePath') . '/' . $campaign->html_file,
            'SegmentIDs' => [$campaign->segment_id]
        ]));

        // Request was successful, we can end the loop.
        $cmCreationTries = 4;
    } catch (CurlException $e) {
        // Try again
        $cmCreationTries++;
    }
} while ($cmCreationTries < 3);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用C语言输入方程怎么
    • ¥15 网站显示不安全连接问题
    • ¥15 github训练的模型参数无法下载
    • ¥15 51单片机显示器问题
    • ¥20 关于#qt#的问题:Qt代码的移植问题
    • ¥50 求图像处理的matlab方案
    • ¥50 winform中使用edge的Kiosk模式
    • ¥15 关于#python#的问题:功能监听网页
    • ¥15 怎么让wx群机器人发送音乐
    • ¥15 fesafe材料库问题