Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110194 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14197 invoked from network); 16 May 2020 21:52:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 May 2020 21:52:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2BC6E1804E0 for ; Sat, 16 May 2020 13:30:38 -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=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS6724 85.215.255.0/24 X-Spam-Virus: No X-Envelope-From: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 16 May 2020 13:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1589661035; s=strato-dkim-0002; d=kelunik.com; h=Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=+Ft46FsBol5o2oVJucJdtHJgwlXvx6B2/jjb/GCu3Ec=; b=qT7l8YZCU8cjajyefMZQXrvoLQ5uFxdc9+wNdMBpvWA//CPixp4exxFAd1GHasVQzh Psd9djXQjnJEyEZSycAfkYHUtB7MGAlRHhoejjIqcpJSTeDeGv1nIRU30z+pOMXKIqRT Yy9Kd6rcs1rFM4Kv4HMVl64I+Z+b6HO/cVQuKMZ+vV7L7mhSrvpuG/u1+Zs09reKodlI QhAa/7GhcW6B120D9ihB4eQeB5iPdra5YbcF455FplVZh6Svx2pJ2AzsW0QPPVaI0zcg NtqgTUDM66CoN+xYPnU98Iw3Mb5BzD9pwU4fUJR6m0JII0rB6yks5me0uXf2oEZERtoe cDTA== X-RZG-AUTH: ":IWkkfkWkbvHsXQGmRYmUo9mlsGbEv0XHBzMIJSS+jKTzde5mDb8Aa6p6x/gl3g==" X-RZG-CLASS-ID: mo00 Received: from mail-vk1-f175.google.com by smtp.strato.de (RZmta 46.6.2 AUTH) with ESMTPSA id C0794aw4GKUYnTx (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Sat, 16 May 2020 22:30:34 +0200 (CEST) Received: by mail-vk1-f175.google.com with SMTP id v23so1462383vke.13 for ; Sat, 16 May 2020 13:30:34 -0700 (PDT) X-Gm-Message-State: AOAM532mPKzE2rfB1kZaA3GAS+U7r/iI22itYLvThpJdpnPII+EZa0ux H8OhnFUY/CEAxEg85s5PC+h32AY/gkQjAzEJlOY= X-Google-Smtp-Source: ABdhPJyfaFikZi7zWgetlM5L6cOr3DZNFoNR/ExiFKBLyT7zLo0/VDLZur6Fo+EK1k5Zkcy3GLJ/8ox4BRhMt0Ky2Rk= X-Received: by 2002:a1f:25d7:: with SMTP id l206mr6788639vkl.53.1589661034170; Sat, 16 May 2020 13:30:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 16 May 2020 22:29:48 +0200 X-Gmail-Original-Message-ID: Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000041515305a5c9cd90" Subject: Re: [PHP-DEV] Graceful timeout From: me@kelunik.com (Niklas Keller) --00000000000041515305a5c9cd90 Content-Type: text/plain; charset="UTF-8" Hey David, I guess you're looking for a preemptive timeout. I guess an alarm signal and PHP's async signal handling will be your best bet here. In case you're looking for a cooperative timeout, https://amphp.org/ and it's `Amp\Promise\timeout()` / `TimeoutCancellationToken` might be helpful. Best, Niklas Am Sa., 16. Mai 2020 um 19:41 Uhr schrieb David Rodrigues < david.proweb@gmail.com>: > 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 limit > processing and stop when the time limit is recovered. > > $completeRun = 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 > --00000000000041515305a5c9cd90--