Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99551 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89155 invoked from network); 19 Jun 2017 15:03:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jun 2017 15:03:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.192.178 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.192.178 mail-pf0-f178.google.com Received: from [209.85.192.178] ([209.85.192.178:35777] helo=mail-pf0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/F7-13828-0D7E7495 for ; Mon, 19 Jun 2017 11:03:45 -0400 Received: by mail-pf0-f178.google.com with SMTP id l89so55029012pfi.2 for ; Mon, 19 Jun 2017 08:03:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ynIviae864sqswfSLi1MDvOuyJnaxsEd7tUx3HDhrKk=; b=gMRUXgU4s1/chCUk5Chn7Y/+orNV0gTurr+INyBSIF7j3XGSlgbozbKs1HVm6N4fPe uM/Mdju2EZN3w5mrtqJRQnfZZLTgKU4qefYQVYja1tDrCMLf64yUmIY0KGRb2lkIKprP zPcqHF68rNgzHsOCJ1lmQ2+kkmIMAp00ZhjRq526IsVSZi4eMTZh1Dh/gHgzYeA0wPQO mgS5EdwvanUdsnerhOrDe5gIht3jI0sytI4tDH84PCE3k+eiMF/83K6+vDtuQI/47+6q kPpzwcqqAhm2k/gP8fQ1EOLfV1KPNBtR9OG7fqg+673VbFK+cjWCyf59hPdBtweG5SPq Ng6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ynIviae864sqswfSLi1MDvOuyJnaxsEd7tUx3HDhrKk=; b=aV6fm3XN0gC5N1cXJi/4YTE0g++oU1mY7DWFNhgLXKAVcuYMctvGC2++Qxm9ToVCL0 kw8mjBfs0xJlMgJ7xjecMHG2VzIFOSYPCvCVR6ZsrgDNs+16YsNYTB833DosFxvKivXd oj5yvM344KNG0KSte6Yd5sqRDkOueyygiIB1DXWQcZRMoxPTS+9FoCG5wlu3o2vfqRo6 q/i+S0AHG2eB+zyXq4e/y5j69K6XBmjmJ/ECx4F45q+vlK8EowJ7RFWs2VahjK1ei9vm /ubXFy4YJQ0RyX4StNE5YDXdBAjsrkf7sjBJlsYXsGAt066yEDxEVfw/In+CTj3pY55k 0YoA== X-Gm-Message-State: AKS2vOzNP5hHJ4UGLiyJnJMr1qRokKeKgCg0j9KaMSJP3W9FykJIz3oJ 9QkbgwxvhRzW28J3ppuSshpQvX+iEvAu X-Received: by 10.98.103.12 with SMTP id b12mr25636237pfc.171.1497884620905; Mon, 19 Jun 2017 08:03:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.168.4 with HTTP; Mon, 19 Jun 2017 08:03:40 -0700 (PDT) X-Originating-IP: [81.143.203.71] In-Reply-To: References: Date: Mon, 19 Jun 2017 16:03:40 +0100 Message-ID: To: Sammy Kaye Powers Cc: PHP Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] [Discussion] Retry functionality From: danack@basereality.com (Dan Ackroyd) Hi Sammy, On 19 June 2017 at 14:55, Sammy Kaye Powers wrote: > Hello internals! Please could you add to the RFC a description of what a 'break' in a retry block actually does? Although there is an example for it, and so people can guess what it does, having it described clearly would be better. Could you also confirm, the number of retries can't be an expression, right? i.e. the number of retries has to be hard-coded into the script? I don't believe the section "check out a full userland implementation that covers all the features of the example above with a fully-featured retry() function." is a valid comparison, and certainly not how I (and I suspect other people) write re-attempt code. For me it is much more normal to just use an in place for($attempt.....) loop. A for-loop based equivalent of the example from the RFC is below. Although it is a couple of lines longer than the 'retry' version, it's not drastically longer. It also has the benefit of not having a piece of data (the number of retry attempts) be hard-coded into the PHP script that does the retrying. > It forces the developer to make extra methods or functions, tbh - that sounds like a good thing. One function to attempt the thing, and another function to decide whether to retry or do something else. cheers Dan for ($attempt=0; ; $attempt++) { $id = 42; try { throw new RecoverableException("FAILED getting ID #{$id}"); break; // obviously this won't be reached - but is here for completeness } catch (RecoverableException | AnotherRecoverableException $e) { if ($attempt > MAX_RETRY_ATTEMPTS) { echo $e->getMessage(); throw $e; } if (42 === $e->getCode()) { throw $e; } echo "Failed getting ID #{$id} on try #{$attempt}. Retrying..."; sleep(1); } catch (NonRecoverableException $e) { echo $e->getMessage(); throw $e; } }