Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110190 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87243 invoked from network); 16 May 2020 19:37:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 May 2020 19:37:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E9F791804E4 for ; Sat, 16 May 2020 11:15:23 -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.1 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_NEUTRAL autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS30827 82.113.144.0/21 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Sat, 16 May 2020 11:15:23 -0700 (PDT) Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 3AF2010C087; Sat, 16 May 2020 19:15:23 +0100 (BST) Date: Sat, 16 May 2020 19:15:23 +0100 (BST) X-X-Sender: derick@singlemalt.home.derickrethans.nl To: David Rodrigues cc: PHP Internals In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [PHP-DEV] Graceful timeout From: derick@php.net (Derick Rethans) Hi David, On Sat, 16 May 2020, David Rodrigues wrote: > 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. You can set-up a shutdown handler though, which will get called. > > 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); sleep(2) should not trigger a 1 second timeout. Currently the time counted for max_execution_time timeouts is CPU time, not wall time. You can probably implement this already with PHP's tick functionality (https://www.php.net/manual/en/function.register-tick-function.php), as long as the code in the anonymous function does PHP statements/function calls. If your problem is waiting for an external resource to be available (database call, http call), then instead you should be able to use functionality of these services to handle your timeouts. cheers, Derick -- PHP 7.4 Release Manager Host of PHP Internals News: https://phpinternals.news Like Xdebug? Consider supporting me: https://xdebug.org/support https://derickrethans.nl | https://xdebug.org | https://dram.io twitter: @derickr and @xdebug