【问题标题】:GitHub Actions - PHP Fatal error: Allowed memory size of 1073741824 bytes exhaustedGitHub Actions - PHP 致命错误:允许的内存大小为 1073741824 字节已用尽
【发布时间】:2021-04-21 05:38:03
【问题描述】:

我正在尝试在 GitHub Actions 上为 Laravel 应用程序运行功能测试。测试在本地运行良好,但是当 GitHub Actions 触发时,我收到内存大小错误。如何避免这种情况并在 GitHub Actions 服务器上成功运行测试?

这是我们设置的 github action YML 文件:

jobs:
  laravel-feature-tests:
    runs-on: ubuntu-latest
    name: Feature tests

    steps:
    ...
    - uses: shivammathur/setup-php@v2
      with:
        php-version: '7.3'
        extensions: gd, mysql
        tools: composer:v1
    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
    - name: Execute Feature tests via PHPUnit
      run: vendor/bin/phpunit --testsuite Feature

这是 GitHub 中的失败:


Run vendor/bin/phpunit --testsuite Feature
PHPUnit 6.0.8 by Sebastian Bergmann and contributors.

................................................................  63 / 750 (  8%)
............................................................... 126 / 750 ( 16%)
PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in <project>/vendor/symfony/routing/RouteCompiler.php on line 188

我们可以做些什么来绕过这个Allowed memory size exhausted 错误来使用 GitHub Actions 运行我们的测试?

【问题讨论】:

  • 您尝试过什么调试问题?为什么这个问题被标记为composer-php
  • 我认为这可能与作曲家任务有关。我会删除标签

标签: php phpunit github-actions


【解决方案1】:

我在一个正在测试的控制器路由中设置了内存限制。删除此行或将内存限制加倍允许测试通过:

public function myRoute(Request $request)
{
    ini_set('memory_limit', '1024M'); // <-- removing this line or setting to 2048M worked

【讨论】:

  • 为什么你有那条线,并且在控制器中?这是一个禁忌!
猜你喜欢
  • 2016-09-24
  • 2019-05-21
  • 2017-11-06
  • 2015-07-06
  • 2018-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-07
相关资源
最近更新 更多