-
Notifications
You must be signed in to change notification settings - Fork 19
fix: Inherit PHP settings from the main process #307
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
Open
theofidry
wants to merge
4
commits into
webmozarts:3.x
Choose a base branch
from
theofidry:fix/mem-limit
base: 3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ final class SymfonyProcessLauncher implements ProcessLauncher | |
* @param callable(): void $tick | ||
*/ | ||
public function __construct( | ||
private readonly string $phpExecutable, | ||
private readonly array $command, | ||
private readonly string $workingDirectory, | ||
private readonly ?array $environmentVariables, | ||
|
@@ -135,6 +136,7 @@ private function startProcess(InputStream $inputStream): void | |
$process = $this->processFactory->startProcess( | ||
$index, | ||
$inputStream, | ||
$this->phpExecutable, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change is a BC break |
||
$this->command, | ||
$this->workingDirectory, | ||
$this->environmentVariables, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Webmozarts Console Parallelization package. | ||
* | ||
* (c) Webmozarts GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webmozarts\Console\Parallelization\Fixtures\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Terminal; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Webmozarts\Console\Parallelization\ErrorHandler\ErrorHandler; | ||
use Webmozarts\Console\Parallelization\Input\ParallelizationInput; | ||
use Webmozarts\Console\Parallelization\Integration\TestDebugProgressBarFactory; | ||
use Webmozarts\Console\Parallelization\Integration\TestLogger; | ||
use Webmozarts\Console\Parallelization\Logger\Logger; | ||
use Webmozarts\Console\Parallelization\Logger\NullLogger; | ||
use Webmozarts\Console\Parallelization\Logger\StandardLogger; | ||
use Webmozarts\Console\Parallelization\ParallelExecutorFactory; | ||
use Webmozarts\Console\Parallelization\Parallelization; | ||
use function file_get_contents; | ||
use function ini_get; | ||
use function json_decode; | ||
use function realpath; | ||
use const JSON_THROW_ON_ERROR; | ||
|
||
final class PhpSettingsCommand extends Command | ||
{ | ||
use Parallelization; | ||
|
||
public const OUTPUT_DIR = __DIR__.'/../../../dist/php-settings'; | ||
|
||
public function __construct( | ||
private Filesystem $filesystem, | ||
) { | ||
parent::__construct('test:php-settings'); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
ParallelizationInput::configureCommand($this); | ||
} | ||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
protected function fetchItems(InputInterface $input, OutputInterface $output): array | ||
{ | ||
return ['item0']; | ||
} | ||
|
||
protected function getParallelExecutableFactory( | ||
callable $fetchItems, | ||
callable $runSingleCommand, | ||
callable $getItemName, | ||
string $commandName, | ||
InputDefinition $commandDefinition, | ||
ErrorHandler $errorHandler | ||
): ParallelExecutorFactory { | ||
return ParallelExecutorFactory::create( | ||
$fetchItems, | ||
$runSingleCommand, | ||
$getItemName, | ||
$commandName, | ||
$commandDefinition, | ||
$errorHandler, | ||
) | ||
->withRunBeforeFirstCommand(self::runBeforeFirstCommand(...)) | ||
->withScriptPath(realpath(__DIR__.'/../../../bin/console')); | ||
} | ||
|
||
private function runBeforeFirstCommand(): void | ||
{ | ||
$this->filesystem->dumpFile( | ||
self::OUTPUT_DIR.'_main_process', | ||
ini_get('memory_limit'), | ||
); | ||
} | ||
|
||
protected function runSingleCommand(string $item, InputInterface $input, OutputInterface $output): void | ||
{ | ||
$this->filesystem->dumpFile( | ||
self::OUTPUT_DIR, | ||
ini_get('memory_limit'), | ||
); | ||
} | ||
|
||
protected function getItemName(?int $count): string | ||
{ | ||
return 1 === $count ? 'item' : 'items'; | ||
} | ||
|
||
protected function createLogger(InputInterface $input, OutputInterface $output): Logger | ||
{ | ||
return new NullLogger(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Webmozarts Console Parallelization package. | ||
* | ||
* (c) Webmozarts GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webmozarts\Console\Parallelization\Integration; | ||
|
||
use PHPUnit\Framework\Attributes\CoversNothing; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\Process\Process; | ||
use Webmozarts\Console\Parallelization\Fixtures\Command\ImportMoviesCommand; | ||
use Webmozarts\Console\Parallelization\Fixtures\Command\ImportUnknownMoviesCountCommand; | ||
use Webmozarts\Console\Parallelization\Fixtures\Command\LegacyCommand; | ||
use Webmozarts\Console\Parallelization\Fixtures\Command\NoSubProcessCommand; | ||
use Webmozarts\Console\Parallelization\Fixtures\Command\PhpSettingsCommand; | ||
use Webmozarts\Console\Parallelization\Integration\BareKernel; | ||
use Webmozarts\Console\Parallelization\Integration\OutputNormalizer; | ||
use Webmozarts\Console\Parallelization\Integration\TestLogger; | ||
use function array_column; | ||
use function array_map; | ||
use function file_get_contents; | ||
use function preg_replace; | ||
use function spl_object_id; | ||
use function str_replace; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[CoversNothing] | ||
class PhpProcessSettingsTest extends TestCase | ||
{ | ||
public function test_it_can_run_the_command_without_sub_processes(): void | ||
{ | ||
$commandProcess = Process::fromShellCommandline( | ||
'php -dmemory_limit="256M" bin/console test:php-settings', | ||
__DIR__.'/../..', | ||
); | ||
$commandProcess->run(); | ||
|
||
$expectedMainProcessMemoryLimit = '256M'; | ||
$actualMainProcessMemoryLimit = file_get_contents(PhpSettingsCommand::OUTPUT_DIR.'_main_process'); | ||
|
||
$expectedChildProcessMemoryLimit = '256M'; | ||
$actualChildProcessMemoryLimit = file_get_contents(PhpSettingsCommand::OUTPUT_DIR); | ||
|
||
self::assertSame( | ||
[ | ||
$expectedMainProcessMemoryLimit, | ||
$expectedChildProcessMemoryLimit, | ||
], | ||
[ | ||
$actualMainProcessMemoryLimit, | ||
$actualChildProcessMemoryLimit, | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be able to pass the PHP executable to
PhpSubprocess
we need to expose it, instead of passing it as part of the created command