8000 Improving the server:run command · Issue #10827 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Improving the server:run command #10827

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

Closed
javiereguiluz opened this issue Apr 30, 2014 · 23 comments
Closed

Improving the server:run command #10827

javiereguiluz opened this issue Apr 30, 2014 · 23 comments
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) FrameworkBundle

Comments

@javiereguiluz
Copy link
Member

The problem

The server:run command is both good and bad for beginners. It's good because it makes unnecessary to mess with Apache configuration. But it's bad because executing it blocks the console:

$ php app/console server:run
Server running on localhost:8000

As server:run doesn't return the user to the regular shell, he/she needs to open another console or he/she needs to launch the command in the background (server run &).

The proposed solution

I'd like to replace the current server:run command with three new commands modeled after the traditional web servers:

  • server:start, it launches the built-in web server in the background and return the user to the regular shell.
  • server:status, it checks if the server is running and tells you the URL and the port.
  • server:stop, it stops the server launched with the server:start command.

As an added bonus, when launching the built-in server, the command could also check the availability of the 8000 port to choose the next available port number when the 8000 port is already used.

@lyrixx
Copy link
Member
lyrixx commented Apr 30, 2014

Good idea, but instead of replacing, it could be added to existing command.

@fabpot
Copy link
Member
fabpot commented Apr 30, 2014

👍

8000

@stof
Copy link
Member
stof commented Apr 30, 2014

Does PHP support running a background process or will it kill the child process when the PHP process ends ?

@javiereguiluz
Copy link
Member Author

@stof I have no idea, but I trust the ability of @romainneutron, the wizard of the Console and Process components.

@pborreli
Copy link
Contributor

impressed and curious to see how it could work on windows

@RickySu
Copy link
Contributor
RickySu commented May 2, 2014

here is an example to start a daemon (background process).

<?php
$pid = pcntl_fork();

if($pid < 0){ 
    //something wrong
    exit;
}

if($pid > 0){
    //this is parent process.
    echo "child process start with pid $pid";
    exit;
}

posix_setsid(); // detach f
8000
rom current terminal
//daemon process start here

@weaverryan
Copy link
Member

👍 for me too!

@wouterj
Copy link
Member
wouterj commented May 4, 2014

If it's possible for all OS's: a big 👍

@nifr
Copy link
nifr commented May 5, 2014

👍 I like the idea.

@Burgov
Copy link
Contributor
Burgov commented May 5, 2014

i usually run the app with -vvv which shows all server output in the blocking process. This idea would kill that, but if instead of replacing it, it is added to the existing command it's fine.

One problem I do see, though: currently, it's possible to run the server twice for 1 application (with different ports). If the servers are started in the background, how will server:status and server:stop known which one to act upon? Or should running multiple servers for one app be blocked altogether? How should that be enforced? a lock file?

8000

@liuggio
Copy link
Contributor
liuggio commented May 5, 2014

Maybe it's me but I don't see any value from this,
running a daemon from the process shouldn't be an OS issue?

Adding and maintaining PHP classes just for a simple command: nohup app/console server:run &, from the linux prospective I don't see any benefit,
M2C.

@apfelbox
Copy link
Contributor

@Burgov you could just enumerate all different servers or tell the command on which port you want to run - and kill it with this exact port number.

I like the idea 👍

@hhamon
Copy link
Contributor
hhamon commented Jun 18, 2014

👍

@mnapoli
Copy link
Contributor
mnapoli commented Jun 19, 2014

As previously said, please keep server:run :)

And as to how to do it, wouldn't just running app/console server:run & be enough on Unix, and using START be enough on Windows? That would avoid any pcntl_fork() that requires Unix and installing an extension.

To be clear I mean app/console server:start would run app/console server:run & (on Unix).

@javiereguiluz
Copy link
Member Author

@liuggio @mnapoli app/console server:run & is not enough when you run several applications on the same computer. By default the command uses 127.0.0.1:8000 for all applications. This means that for the second app started with server:run you have to change the port number manually ... verifying first that it's free.

In other words, if you just execute one single application at a time, these proposed commands aren't necessary. If you run 3 or more applications, these command would definitely make your life as a developer easier.

@mnapoli
Copy link
Contributor
mnapoli commented Jun 19, 2014

@javiereguiluz I just said "please also keep server:run", I don't see a problem with adding those new commands.

@kingcrunch
Copy link
Contributor

@mnapoli

app/console server:run &

That doesn't detach the process from the current terminals/shell process. This means as soon as you leave the shell, it will also kill the child processes. See nohup.

@mnapoli
Copy link
Contributor
mnapoli commented Jun 19, 2014

@kingcrunch yes nohup, you get what I meant anyway.

@romainneutron
Copy link
Contributor

Hello,

with the upcoming LockFile command helper (it solves @javiereguiluz issue) and the use of pcntl_fork, this could be achieved very well (and it would be stable).

Running the command app/console server:run & is not a solution as long as the process is still attached to the term session.

@dirkluijk
Copy link

👍

@buzzedword
Copy link

I'd be interested in seeing the entire server command evolve into something akin to Laravel's Homestead. If we're talking developer experience here, you really can't beat having your server spun up entirely for you.

Let's talk about issues every time:

  • intl extension
  • apc (and now APCu)
  • mysql configuration
  • apache configuration
  • php opcache (5.5)

This is a nightmare for the average dev, and we're at the point where the server command is a stopgap. The Laravel guys have the right idea providing a preconfigured environment, and we should really be moving towards that. It's super easy to forget just how much Ops is needed to start doing dev.

@stof
Copy link
Member
stof commented Jun 26, 2014

@buzzedword this is not exclusive to improving the FrameworkBundle commands. Providing a VM environment configured to run Symfony is out of the scope of FrameworkBundle though. It is best kept as a separate project (and I think some people already provide such setups in forks of symfony-standard or their own repos).

you might even use Homestead I think, if you adapt the serve script for the Symfony nginx config rather than the Laravel one (which is pretty similar except the name of the front controller script). the requirements of Laravel or Symfony for the dev environment are quite similar

fabpot added a commit that referenced this issue Sep 22, 2014
…l PHP's built-in web server (xabbuh)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[FrameworkBundle] Additional helper commands to control PHP's built-in web server

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10827
| License       | MIT
| Doc PR        | symfony/symfony-docs#4005

Basically, both the ``server:status`` and ``server:stop`` wouldn't be really reliable if you had stopped the web server by, for example, killing the process. But honestly I don't know how to platform-independently determine if a process is still running given its PID. Maybe such a way could be a good improvement for the Process component.

Commits
-------

b601454 new helper commands for PHP's built-in server
@fabpot fabpot closed this as completed Sep 22, 2014
@nifr
Copy link
nifr commented Sep 22, 2014

👍 awesome addition, thanks @fabpot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX DX = Developer eXperience (anything that improves the experience of using Symfony) FrameworkBundle
Projects
None yet
Development

No branches or pull requests

0