Fix: Prevent exception when parsing request port in ServeCommand
Summary
This PR fixes an issue where php artisan serve throws an exception on Windows when a log line does not contain a valid request port.
Problem
"process forking is not supported" when running the "artisan serve", and the flushOutputBuffer method tries to parse invalid lines. This raises the exception
Solution
- Added a guard condition to check if the line contains the expected keywords (
Accepted,Closing) before callinggetRequestPortFromLine. - Ensured no exception is thrown for invalid lines.
Changes Made
- Updated
flushOutputBuffermethod inServeCommand.php:- Added
contains()checks for specific keywords. - Skipped port parsing for invalid lines.
- Added
How to Test
- Run
php artisan serve. - Verify that no exception occurs when invalid lines are logged.
- Check that server output behaves as expected.
Mark as draft since it has a merge conflict.
The error "Failed to extract the request port" is caused by the change from #53887. Which has been reverted in the latest release 11.36.1.
In that PR behaviour was changed by pulling out the common logic of getting the port from a line. Which, previously was behind if-statements.
This PR might not be necessary if #53887 is adjusted so that static::getRequestPortFromLine is not called outside of the if statements again, or if it is not re-introduced.