Repository navigation
max_execution_time reached too early #12814
Description
Activity
Hi @Muffinman. Can you share a bit more about your setup? What web server + SAPI are you using? Are you using Octane or something similar by any chance?
Hi @iluuu1994 ,
I'm running the homebrew compiled php-fpm under nginx.
No octane in use, I only have php-redis and imagick extensions installed via pecl, everything else should be out of the box.
That's odd. macOS should use (AFAIK)
setitimer(ITIMER_REAL, ...)which doesn't even include IO time. So if anything, your request should allow to run for longer than the configuredmax_execution_time. Is this issue restricted to macOS or does it also occur on other operating systems?I've only seen it on MacOS.
One other thing I've noticed is that if I replace the call to
Category::rebuildTree()with a simplesleep(5), then the timeout problem does not happen, even though the request takes longer.There must be something deep in that code which is causing PHP either to throw the wrong exception, or otherwise somehow miscount it's execution time.
Unfortunately I don't have a (working) macOS machine to test this. Some minimal reproducer would be great, although I understand this might be tricky. It's also hard to rule out an error in php-redis itself.
Well I think I've managed to rule out
php-redis, if I switch all the Laravel queue/cache drivers away from Redis themax_execution_timeexception still happens, but instead happens in some Guzzle code.Will keep experimenting to see if I can narrow it down further.
Reacted by Ilija Tovilo, Jack Webb-Heller and Vakil-Parth@Muffinman I've got exactly the same issue, relieved to see it's not just me! Have you been able to find any clues?
In my case this affects both PHP
8.2.13, and a fresh clean install of PHP8.3.0. Both running on macOS 14.1.2 using Valet (php-fpm + nginx). However, I was tipped off to the issue after a random page on my production server (running Ubuntu 18, PHP 8.2 and nginx) started throwing HTTP 500s and timing out. So this possibly also affects non-Mac environments as well.Unfortunately it's not easy to debug further on production at the moment, as I've since had to make a short-term workaround to get the page running again. If any more clues come up I can try some specific tests though.
Other things I've noticed:
- No consistency in terms of which line throws the error, it just seems to get tangled up in various framework code each time
- If I add
ini_set('max_execution_time', -1)the page loads after 2 or 3 seconds. - If I change it to
ini_set('max_execution_time', 30)(or 20, or 10, etc.) it still throws the error almost immediately. The error message also updates to show the configured timeout (e.g "Maximum execution time of 20 seconds"), so I know it's taking effect. - I've searched the entire codebase (including
vendor) for any scripts which might be overridingmax_execution_time,set_time_limit(...), etc. but there are no occurrences
Reacted by Mitch Musarra, Petar Španja, Jan Pfau and Rajesh SharmaCan any of you provide a reproducible codebase? If so, you can send it to me privately over email. If possible without dependencies (databases and whatnot).
No I didn't manage to track it down unfortunately. In my case I was able to mitigate it by pausing the Model events in Laravel.
I think it should be possible to create minimal a reproduction repo.
Reacted by Ilija Tovilo54 remaining items
I was able to reproduce the issue on an M2 Pro with latest Sonoma (14.5). This is reproducible in pure C, and appears to be triggered/accelerated by other syscalls: https://gist.github.com/arnaud-lb/012195a2fe4d3a2c1bff530a73ae6b11
Switching to ITIMER_REAL fixes the issue in both PHP and the C reproducer.
Reacted by Nick IvanterReacted by Hugo AlliaumeI've sent a message to internals and will merge #13567 if there are no objections.
Reacted by Nick IvanterReacted by Manuel Kress, Hugo Alliaume and Jakob Larsen@arnaud-lb Did they reply yet? 😅
There are no objections so far, so I will merge next week if it continues like that.
Reacted by Ilija Tovilo, Kévin Dunglas, Manuel Kress, Hugo Alliaume and chrisReacted by Hugo Alliaume- added a commit that references this issue
on May 28, 2024 #13567 is now merged in 8.2 and 8.3.
Reacted by Manuel Kress, Jack Webb-Heller, Camille Hodoul and chrisI was seeing this on macOS and it was very puzzling! Glad to see it fixed in the latest release!
Reacted by Jérémy DECOOL and Nikitchenko SergeyI've just upgraded PHP to 8.3.9 on M1 and here's what I see when running Psalm:
> php -v PHP 8.3.9 (cli) (built: Jul 2 2024 14:10:14) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.9, Copyright (c) Zend Technologies with Zend OPcache v8.3.9, Copyright (c), by Zend Technologies with blackfire v1.92.18~mac-x64-non_zts83, https://blackfire.io, by Blackfire > tools/psalm/vendor/bin/psalm --show-info --no-diff '--no-cache' Target PHP version: 8.1 (inferred from composer.json) Enabled extensions: random. Scanning files... Analyzing files... ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 60 / 236 (25%) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 236 (50%) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 236 (76%) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░PHP Fatal error: Maximum execution time of 0 seconds exceeded in /Users/vudaltsov/Projects/typhoon/typhoon/tools/psalm/vendor/vimeo/psalm/src/Psalm/Internal/Type/ParseTree.php on line 26 Fatal error: Maximum execution time of 0 seconds exceeded in /Users/vudaltsov/Projects/typhoon/typhoon/tools/psalm/vendor/vimeo/psalm/src/Psalm/Internal/Type/ParseTree.php on line 26 ------------------------------ No errors found! ------------------------------ Psalm can automatically fix 6 of these issues. Run Psalm again with --alter --issues=MissingParamType --dry-run to see what it can fix. ------------------------------ Checks took 5.10 seconds and used 177.671MB of memory Psalm was able to infer types for 99.4033% of the codebaseNever had this issue before. Could this be related?
Interestingly the error is not thrown when running psalm with
--threads=1.Reacted by Thomas David BakerI'm still seeing the timeout error on my M1 mac, PHP 8.1.29. Was the fix only in 8.2 and 8.3?
Was the fix only in 8.2 and 8.3?
It seems. PHP 8.1 is not actively maintained anymore.
I use Homebrew throught https://github.com/shivammathur/homebrew-php which contains a patch for 8.1
I started seeing the same issue as @vudaltsov after upgrading from a 8.3.x version (don't remember which) to 8.3.9.
Also using homebrew PHP in a M3.
--threads=1does stop that error for me as well.Reacted by Valentin Udaltsov and Vakil-ParthShould we create a separate issue and a reproducer for this?
Reacted by thomashohn
Description
Hi, I'm looking for some guidance in tracking down a very strange error with
max_execution_timesetting not being honoured correctly.We have an incoming JSON POST request to a Laravel backend, which does some processing and stores some data.
The request is a few KB of tree data, and the controller calls a
rebuildTree()method as below. Internally this makes a lot of calls to the MySQL DB and Redis DB.The problem I'm facing is that this fails every time after 1 second with this error:
I have added some debugging to the exception handler to try to work out why it is doing this:
Now for the next strange part, if I set the
max_execution_timeto some other far larger value, it works!PHP Version
PHP 8.2.13
Operating System
MacOS 14.1.1