-
-
Notifications
You must be signed in to change notification settings - Fork 22
Fix Windows proc_open pipe error using Runner interface pattern #84
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
Copilot
wants to merge
23
commits into
master
Choose a base branch
from
copilot/fix-windows-support-issue
base: master
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 all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
55956d4
Initial plan
Copilot dc157b5
Fix Windows pipe error by using correct descriptor specs and bypass_s…
Copilot a95ba52
Improve type annotations based on code review feedback
Copilot 89f4d5e
Refactor to use Runner interface pattern to abstract platform-specifi…
Copilot 270858c
Clean up unnecessary state tracking in WindowsProcessRunner
Copilot 700e4e3
Move proc_open logic into ProcessRunner implementations for cleaner a…
Copilot 095a831
Add @return resource docblocks to ProcessRunner implementations
Copilot 2f5a450
Pass environment variables to proc_open instead of using putenv
Copilot c91407e
Rename ProcessRunner to ProcessRunnerInterface and move implementatio…
Copilot 9fd80b0
Fix Windows CI: remove shell redirection when using proc_open descrip…
Copilot edbb5c0
Remove @internal annotations to fix phan errors
Copilot 50aaab4
Apply code review feedback: fix env vars, cleanup temp files, improve…
Copilot baa402d
Merge master into copilot/fix-windows-support-issue
Copilot 19a71cf
Fix Windows server startup by using bypass_shell=true with array desc…
Copilot ab0f650
Move command building into ProcessRunner implementations
Copilot 121b911
Introduce AbstractProcessRunner with shared temp-file cleanup and pre…
Copilot 581c9f7
Use getenv() instead of $_SERVER to build parent environment
Copilot eb633e9
Move process lifecycle management to AbstractProcessRunner
donatj cd510f0
Extract temp file creation and remove cleanup logic
donatj 348be61
Replace shutdown function with ProcessRunner destructor
donatj 69f96fb
Add macOS to CI test matrix
donatj 0a327d0
Add PHPStan assertion to isRunning and simplify stop
donatj ff68a6d
Fix PHPStan type errors in ProcessRunner implementations
donatj 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?php | ||
|
|
||
| namespace donatj\MockWebServer\Exceptions; | ||
|
|
||
| class TempFileException extends RuntimeException { | ||
|
|
||
| } |
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,36 @@ | ||
| <?php | ||
|
|
||
| namespace donatj\MockWebServer; | ||
|
|
||
| /** | ||
| * Interface for platform-specific process execution | ||
| */ | ||
| interface ProcessRunnerInterface { | ||
|
|
||
| /** | ||
| * Start a PHP built-in server process | ||
| * | ||
| * @param string $phpBinary Path to the PHP binary | ||
| * @param string $host Hostname to listen on | ||
| * @param int $port Port to listen on | ||
| * @param string $script Path to the server script | ||
| * @param array<string,string> $env Environment variables to pass to the process | ||
| * @throws \donatj\MockWebServer\Exceptions\ServerException If the process fails to start | ||
| * @throws \donatj\MockWebServer\Exceptions\RuntimeException If temp file or stream operations fail | ||
| * @return resource The process resource | ||
| */ | ||
| public function startProcess( string $phpBinary, string $host, int $port, string $script, array $env = [] ); | ||
|
|
||
| /** | ||
| * Is the process currently running? | ||
| */ | ||
| public function isRunning() : bool; | ||
|
|
||
| /** | ||
| * Stop the running process | ||
| * | ||
| * @throws \donatj\MockWebServer\Exceptions\ServerException If the process fails to stop | ||
| */ | ||
| public function stop() : void; | ||
|
|
||
| } | ||
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,79 @@ | ||
| <?php | ||
|
|
||
| namespace donatj\MockWebServer\ProcessRunners; | ||
|
|
||
| use donatj\MockWebServer\Exceptions\ServerException; | ||
| use donatj\MockWebServer\Exceptions\TempFileException; | ||
| use donatj\MockWebServer\ProcessRunnerInterface; | ||
|
|
||
| /** | ||
| * Abstract base for platform-specific process runners. | ||
| * | ||
| * Provides shared temporary-file tracking and cleanup logic. | ||
| */ | ||
| abstract class AbstractProcessRunner implements ProcessRunnerInterface { | ||
|
|
||
| public const STDOUT_PREFIX = 'MockWebServer.stdout'; | ||
| public const STDERR_PREFIX = 'MockWebServer.stderr'; | ||
|
|
||
| /** @var resource|null */ | ||
| protected $process; | ||
|
|
||
| /** | ||
| * Ensure the process is stopped when the object is destroyed | ||
| */ | ||
| public function __destruct() { | ||
| $this->stop(); | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-assert-if-true resource $this->process | ||
| */ | ||
| public function isRunning() : bool { | ||
| if( !is_resource($this->process) ) { | ||
| return false; | ||
| } | ||
|
|
||
| $processStatus = proc_get_status($this->process); | ||
|
|
||
| if( !$processStatus ) { | ||
| return false; | ||
| } | ||
|
|
||
| return $processStatus['running']; | ||
| } | ||
|
|
||
| public function stop() : void { | ||
| if( !$this->isRunning() ) { | ||
| return; | ||
| } | ||
|
|
||
| proc_terminate($this->process); | ||
|
|
||
| $attempts = 0; | ||
| while( $this->isRunning() ) { | ||
| if( ++$attempts > 1000 ) { | ||
| throw new ServerException('Failed to stop server.'); | ||
| } | ||
|
|
||
| usleep(10000); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a temporary file | ||
| * | ||
| * @param string $prefix Prefix for the temp file name | ||
| * @throws TempFileException If temp file creation fails | ||
| * @return string Path to the created temp file | ||
| */ | ||
| protected function createTempFile( string $prefix ) : string { | ||
| $tempFile = tempnam(sys_get_temp_dir(), $prefix); | ||
| if( $tempFile === false ) { | ||
| throw new TempFileException("error creating temp file with prefix '{$prefix}'"); | ||
| } | ||
|
|
||
| return $tempFile; | ||
| } | ||
|
|
||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.