Skip to content

System hangs when a php interpreter is executed via Process #49320

Closed
@isdn

Description

@isdn

Symfony version(s) affected

6.2.6

Description

Server setup:

PHP: 8.2.2
Server API: CGI/FastCGI

When I run a PHP script via Process, Symfony creates lots of /usr/lib/cgi-bin/php8.2 processes, which consume all RAM, server hangs and the OOM killer terminates all Apache instances.

How to reproduce

  1. Create a test project:
composer create-project symfony/skeleton:"6.2.*" testing
cd testing
composer require symfony/apache-pack
composer require symfony/process
  1. config/routes.yaml :
controllers:
    resource:
        path: ../src/Controller/
        namespace: App\Controller
    type: attribute
test:
    path: /test
    controller: App\Controller\Test::test
  1. src/Controller/Test.php:
<?php

namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

class Test
{
    public function test(): Response
    {
        $phpBinaryPath = (new PhpExecutableFinder())->find();
        $process = new Process([$phpBinaryPath, './test.php']);

        try {
            $process->run();

            if (!$process->isSuccessful()) {
                throw new ProcessFailedException($process);
            }
        } catch (\Exception $e) {
            throw new ProcessFailedException($process);
        }

        return new Response(
            'result: ' . $process->getOutput()
        );
    }
}
  1. public/test.php:
<?php echo 'OK';

Now open the path /test in your web browser.
Symfony starts lots of /usr/lib/cgi-bin/php8.2 processes, which consume all memory and CPU.

I supposed that the issue might be related to HTTP headers, generated by the CGI version.
However, this does not help - new Process([$phpBinaryPath, '-q', './test.php']).

If I run either command directly on the server, all is good - /usr/lib/cgi-bin/php8.2 ./test.php / /usr/lib/cgi-bin/php8.2 -q ./test.php.

If I hardcode the path to CLI PHP ($phpBinaryPath = '/bin/php';) that test script works correctly.

Possible Solution

PhpExecutableFinder should probably return the CLI version instead of CGI.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions