Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to log the request uri when fatal errors encountered. #324

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

nicksantamaria
Copy link
Contributor

Motivation

We're working on reducing the PHP memory limit to ensure that we can run more concurrent workloads efficiently. There will be a period of tuning where we have to locate some areas of the application which need more memory.

Unfortunately the default php-fpm error logs do not output enough information information for us to determine what drupal routes cause a particular problem.

Changes

This PR adds a new error handler which outputs a log entry including the value of $_SERVER['REQUEST_URI']. This error handling is conditionally included when the following environment variable is set

BAY_PHP_FATAL_LOGS=true

When hitting a memory exhausted error now, it should output to the php-fpm container's stdout -

NOTICE: PHP message: [BAY_FATAL] {"type":"E_ERROR","message":"Allowed memory size of 134217728 bytes exhausted (tried to allocate 1052672 bytes)","request_uri":"\/foo\/bar"}

Testing

Once you've got this code available on your test environment, enable the feature with the above environment variable. You can then hack in this code to settings.php below where the log file is included to induce a memory limit error.

ini_set('memory_limit', '128M');

$array = [];
while (true) {
  // Allocate 1MB blocks of memory until the memory limit is exceeded
  $array[] = str_repeat('x', 1024 * 1024);
}

@nicksantamaria nicksantamaria requested a review from GROwen October 31, 2024 04:27
@nicksantamaria nicksantamaria merged commit 930ce50 into 6.x Oct 31, 2024
1 check passed
@nicksantamaria nicksantamaria deleted the feature/enhanced-php-fatal-logs branch October 31, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant