Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110193 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4355 invoked from network); 16 May 2020 20:57:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 May 2020 20:57:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 28F8A1804E3 for ; Sat, 16 May 2020 12:35:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS48854 94.231.96.0/20 X-Spam-Virus: No X-Envelope-From: Received: from smtp.simply.com (smtp.simply.com [94.231.106.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 16 May 2020 12:34:58 -0700 (PDT) Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by smtp.simply.com (Simply.com) with ESMTPSA id 49Pb8J6YFXz61W2 for ; Sat, 16 May 2020 21:34:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=givoni.dk; s=unoeuro; t=1589657696; bh=vHriOnUuOFge2mKT1i38TXW/GZ5EdZkqXWLLHJK7+YU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LoS4UPHpq96OtGg+cOn1t3kWenxl2E9yOkICy+IEWLWaMkSu4C1SrxFNk0MFxm5kB ol9190MqXM9TX+Y0xkoASMQEmuhp/Zt31s+J/2boSQMVQGl5ADijoYINU8ayqgpJ/c srtzYeK0jXhqNbUdCOePOGOId4XcpX21rqETVc/A= Received: by mail-wr1-f41.google.com with SMTP id l18so7255541wrn.6 for ; Sat, 16 May 2020 12:34:56 -0700 (PDT) X-Gm-Message-State: AOAM532U6YO4xY7Iv/XCmZkFFbZRxuGX06R7/jLEam6cRF9RsIIOSeEt fLKXGC8yzxnfWX4tbi2HZEIyufT1P2qrm9V805E= X-Google-Smtp-Source: ABdhPJzYNlexxMPUoSEtbEdGpchTuOEasK/Jap9/CyMz3a4GOT8qoD+g5O+HChRPUtd2bbb3qsyLjCX/UIl54rowEbk= X-Received: by 2002:adf:c381:: with SMTP id p1mr11223551wrf.148.1589657696472; Sat, 16 May 2020 12:34:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 16 May 2020 21:34:45 +0200 X-Gmail-Original-Message-ID: Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000050164f05a5c906b7" Subject: Re: [PHP-DEV] Graceful timeout From: jakob@givoni.dk (Jakob Givoni) --00000000000050164f05a5c906b7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, 16 May 2020 at 19:42, David Rodrigues wrote: > Hello! > > Currently we can use set_time_limit() to specify that our script will run > by some seconds before we get "fatal error: maximum execution time of 1 > second exceeded". And we can't catch it and keep running. > > I believe that it is interesting to create a function that is able to lim= it > processing and stop when the time limit is recovered. > > $completeRun =3D set_time_limit_callback(function () { > sleep(2); > }, 1); > > var_dump($completeRun); > > Where $completeRun will be TRUE only if callback could run until it > returns, and FALSE if timeout. > > It should be very useful when we need works with external resources, like > RESTful, where timeout can occur and we need a better way to work with > that. Or when we have few seconds to run a process. > > What do you think? > > > Atenciosamente, > David Rodrigues Hi David! So you=E2=80=99d like to be able to set a simple timeout on any function ca= ll. I was able to do that with register_tick_function (first time I heard about it!) with a function that throws an exception when the time=E2=80=99s up an= d then surrounding the function call in try/catch. This could probably be turned into a userland =E2=80=9Clibrary=E2=80=9D. I=E2=80=99m not sure how well it would work with real world code though. Fo= r sure, timeouts on http calls must be set on the client handler itself. Best, Jakob > > --00000000000050164f05a5c906b7--