Skip to content
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

PhpServer: Wrap php command with exec #158

Merged
merged 4 commits into from
Apr 14, 2015
Merged

Conversation

fabfuel
Copy link

@fabfuel fabfuel commented Apr 8, 2015

Wrap php command with exec to prevent detached PHP server process on e.g. Debian after stopping the background task.

On Debian, the PHP server process currently does not get killed.
The server gets startet correctly:

vagrant   4233  pts/0    Ss   09:05   0:00  |       \_ -bash
vagrant   5936  pts/0    S+   10:43   0:00  |           \_ php bin/robo server
vagrant   5937  pts/0    S+   10:43   0:00  |               \_ sh -c php -S 0.0.0.0:8000 -t public
vagrant   5938  pts/0    S+   10:43   0:00  |                   \_ php -S 0.0.0.0:8000 -t public

But after finishing the task and stopping the process, the actual PHP server process is still running:

vagrant   5938  pts/0    S    10:43   0:00 php -S 0.0.0.0:8000 -t public

In this example, only the PID 5937 was killed, not the server itself 5938.
Wrapping the php call with exec fixes that issue.

Best
Fabian

@DavertMik
Copy link
Member

Will this work on other systems than Debian?

@burzum
Copy link
Contributor

burzum commented Apr 8, 2015

@fabfuel this change will break the PhpServer on windows. So either find an alternative command for windows (not sure if there is one) or just use exec conditionally when the script is running on a *nix system.

@fabfuel
Copy link
Author

fabfuel commented Apr 9, 2015

You're right, I forgot about Windows... exec works on all Unix based operating systems, including OS X. I did not test Robo on Windows, but if it currently works correct without the exec wrapper, we can skip it.

I now check PHP_OS and only add exec on "linux" environments.

By the way, Symfony does it the same way. As far as I see, they are not checking the OS, but I'm not familiar with Symfony, so maybe there's a magic way how they resolve that:
https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php#L220

Best
Fabian

@fabfuel
Copy link
Author

fabfuel commented Apr 9, 2015

On OS X it also works without the exec wrapper, that's why I check especially for "linux" environments.

@DavertMik
Copy link
Member

Great. Thank you!

DavertMik added a commit that referenced this pull request Apr 14, 2015
PhpServer: Wrap `php` command with `exec`
@DavertMik DavertMik merged commit b529585 into consolidation:master Apr 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants