Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Added server:run command (PHP 5.4 built-in web server)#3465

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 7 commits intosymfony:masterfrommichalpipa:server
Mar 23, 2012

Conversation

@michalpipa
Copy link
Contributor

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass:Build Status
Fixes the following tickets: -
Todo: -

PHP 5.4 comes withbuilt-in web server. I've created command which allows to easily run Symfony2 application using this new feature.

Usage: server:run [-d|--docroot="..."] [-r|--router="..."] [address]Arguments: address        Address:port (default: 'localhost:8000')Options: --docroot (-d) Document root (default: 'web/') --router (-r)  Path to custom router scriptHelp: The server:run runs Symfony2 application using PHP built-in web server:   app/console server:run To change default bind address and port use the address argument:   app/console server:run 127.0.0.1:8080 To change default docroot directory use the --docroot option:   app/console server:run --docroot=htdocs/ If you have custom docroot directory layout, you can specify your own router script using --router option:   app/console server:run --router=app/config/router.php See also: http://www.php.net/manual/en/features.commandline.webserver.php

It requires PHP 5.4, otherwise this command will be disabled.

I think that this is very convenient (especially for new users). All you have to do is download Symfony, install vendors and run this command. You don't have to configure "real" web server, in fact any other server is not required. You don't have cache and logs permission problem, because server runs with your local user permissions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should you use this syntax?

<?phpif (version_compare(phpversion(),'5.4.0','<')) {}else {}

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think that both versions are OK, but mine is simpler.

PHP_VERSION_ID is available since PHP 5.2.7, but you need at least PHP 5.3 to use Symfony2 anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah I don't mind, either are fine, but I thought Symfony used the latter. Just checked and the former is not used at all and the latter is only used in 4 tests, so it doesn't really matter.

@sebhoerl
Copy link
Contributor

Great feature! I was about to write something like this when I saw that you have already started implementing this :)

Some issues:

  1. Missing newlines at the end of the files
  2. If I try this server command with the default Symfony Standard Edition Acme demo the links on the main page do not work. The demo link links to "//demo" and the configurator link to "//_configurator". If I go tolocalhost:8000/demo directly the page is rendered as usual and all sub links are generated correctly. I could solve the problem by adding one line:
$_SERVER['SCRIPT_FILENAME'] = 'ANYTHING';require 'app_dev.php';

I'm not sure where this problem comes from. Do you experience the same behaviour? Otherwise I'll do some more investigations to find the source of the problem.

3 . I think it would be a nice feature if you would generate a router.php based on the setting of the --env flag if no custom router file has been specified. This way it would be easy to switch between dev and prod.

@michalpipa
Copy link
ContributorAuthor

@blogsh

Missing newlines at the end of the files

I've checked and I can see newlines at the end of files. Are you sure about this?

If I try this server command with the default Symfony Standard Edition Acme demo the links on the main page do not work. The demo link links to "//demo" and the configurator link to "//_configurator". If I go to localhost:8000/demo directly the page is rendered as usual and all sub links are generated correctly. I could solve the problem by adding one line:

$_SERVER['SCRIPT_FILENAME'] = 'ANYTHING';require 'app_dev.php';

I'm not sure where this problem comes from. Do you experience the same behaviour? Otherwise I'll do some more investigations to find the source of the problem.

I can reproduce this by changing front controller name fromapp.php toapp_dev.php. I'll investigate on this.

I think it would be a nice feature if you would generate a router.php based on the setting of the --env flag if no custom router file has been specified. This way it would be easy to switch between dev and prod.

You can easily change environment specifying front controller in URL. It works exactly the same way as default Apache configuration. This is intended behavior, as it would be misleading if every server had different rewrite rules.

If you really want to change it, then you can write your own router and pass it as a value torouter option.

@sebhoerl
Copy link
Contributor

Wasn't aware that github omits the trailing white line, sorry.
Normally I use a rather inflexible nginx configuration, so I also wasn't aware of this (rather obvious) trick of changing the url. Thanks for that.

@stof
Copy link
Member

stof commentedMar 6, 2012

@blogsh it does not omit it. It displays it in the Linux way where the newline char is part of the line (and so there is a messageno newline at end of file in the diff when it is missing).

@michalpipa
Copy link
ContributorAuthor

@blogsh I've fixed router script. Now you can use both front controllers.

@michalpipa
Copy link
ContributorAuthor

I've also hardcoded front controller name in router script and removed global variable, as there was no way to unset it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this should beif (!@chdir($docRoot))

@michalpipa
Copy link
ContributorAuthor

I've used Process component, but now I don't get any stdout output (only stderr).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

whyecho ? the way to output something to the console is to use$output

@michalpipa
Copy link
ContributorAuthor

I've replacedecho by$output->write() and removed$process as it was not used actually.

fabpot added a commit that referenced this pull requestMar 23, 2012
Commits-------df11e62 [FrameworkBundle] Used $output->write() instead of echoc3bf479 [FrameworkBundle] Used Process componentcfa2dff [FrameworkBundle] Changed server:run command descriptione7d38c1 [FrameworkBundle] Changed PHP version detection (see:#3529)4a3f6d5 [FrameworkBundle] Removed global variable from router script519d431 [FrameworkBundle] Fixed built-in server router scriptd9a0a17 [FrameworkBundle] Added server:run commandDiscussion----------[FrameworkBundle] Added server:run command (PHP 5.4 built-in web server)Bug fix: noFeature addition: yesBackwards compatibility break: noSymfony2 tests pass: [![Build Status](https://secure.travis-ci.org/michal-pipa/symfony.png?branch=server)](http://travis-ci.org/michal-pipa/symfony)Fixes the following tickets: -Todo: -PHP 5.4 comes with [built-in web server](http://www.php.net/manual/en/features.commandline.webserver.php). I've created command which allows to easily run Symfony2 application using this new feature.    Usage:     server:run [-d|--docroot="..."] [-r|--router="..."] [address]    Arguments:     address        Address:port (default: 'localhost:8000')    Options:     --docroot (-d) Document root (default: 'web/')     --router (-r)  Path to custom router script    Help:     The server:run runs Symfony2 application using PHP built-in web server:       app/console server:run     To change default bind address and port use the address argument:       app/console server:run 127.0.0.1:8080     To change default docroot directory use the --docroot option:       app/console server:run --docroot=htdocs/     If you have custom docroot directory layout, you can specify your own     router script using --router option:       app/console server:run --router=app/config/router.php     See also:http://www.php.net/manual/en/features.commandline.webserver.phpIt requires PHP 5.4, otherwise this command will be disabled.I think that this is very convenient (especially for new users). All you have to do is download Symfony, install vendors and run this command. You don't have to configure "real" web server, in fact any other server is not required. You don't have cache and logs permission problem, because server runs with your local user permissions.---------------------------------------------------------------------------by blogsh at 2012-03-06T17:38:10ZGreat feature! I was about to write something like this when I saw that you have already started implementing this :)Some issues:1. Missing newlines at the end of the files2. If I try this server command with the default Symfony Standard Edition Acme demo the links on the main page do not work. The demo link links to "//demo" and the configurator link to "//_configurator". If I go to `localhost:8000/demo` directly the page is rendered as usual and all sub links are generated correctly. I could solve the problem by adding one line:    $_SERVER['SCRIPT_FILENAME'] = 'ANYTHING';    require 'app_dev.php';I'm not sure where this problem comes from. Do you experience the same behaviour? Otherwise I'll do some more investigations to find the source of the problem.3 . I think it would be a nice feature if you would generate a router.php based on the setting of the --env flag if no custom router file has been specified. This way it would be easy to switch between dev and prod.---------------------------------------------------------------------------by michal-pipa at 2012-03-06T19:00:24Z@blogsh> Missing newlines at the end of the filesI've checked and I can see newlines at the end of files. Are you sure about this?> If I try this server command with the default Symfony Standard Edition Acme demo the links on the main page do not work. The demo link links to "//demo" and the configurator link to "//_configurator". If I go to localhost:8000/demo directly the page is rendered as usual and all sub links are generated correctly. I could solve the problem by adding one line:>>     $_SERVER['SCRIPT_FILENAME'] = 'ANYTHING';>     require 'app_dev.php';>> I'm not sure where this problem comes from. Do you experience the same behaviour? Otherwise I'll do some more investigations to find the source of the problem.I can reproduce this by changing front controller name from  `app.php` to `app_dev.php`. I'll investigate on this.> I think it would be a nice feature if you would generate a router.php based on the setting of the --env flag if no custom router file has been specified. This way it would be easy to switch between dev and prod.You can easily change environment specifying front controller in URL. It works exactly the same way as default Apache configuration. This is intended behavior, as it would be misleading if every server had different rewrite rules.If you really want to change it, then you can write your own router and pass it as a value to `router` option.---------------------------------------------------------------------------by blogsh at 2012-03-06T19:13:55ZWasn't aware that github omits the trailing white line, sorry.Normally I use a rather inflexible nginx configuration, so I also wasn't aware of this (rather obvious) trick of changing the url. Thanks for that.---------------------------------------------------------------------------by stof at 2012-03-06T22:12:16Z@blogsh it does not omit it. It displays it in the Linux way where the newline char is part of the line (and so there is a message ``no newline at end of file`` in the diff when it is missing).---------------------------------------------------------------------------by michal-pipa at 2012-03-07T07:18:23Z@blogsh I've fixed router script. Now you can use both front controllers.---------------------------------------------------------------------------by michal-pipa at 2012-03-07T07:34:58ZI've also hardcoded front controller name in router script and removed global variable, as there was no way to unset it.---------------------------------------------------------------------------by michal-pipa at 2012-03-13T07:57:04ZI've used Process component, but now I don't get any stdout output (only stderr).---------------------------------------------------------------------------by michal-pipa at 2012-03-13T18:01:58ZI've replaced `echo` by `$output->write()` and removed `$process` as it was not used actually.
@fabpotfabpot merged commitdf11e62 intosymfony:masterMar 23, 2012
weaverryan added a commit to symfony/symfony-docs that referenced this pull requestAug 19, 2014
…and (xabbuh)This PR was merged into the 2.3 branch.Discussion----------[Cookbook] add cookbook article for the server:run command| Q             | A| ------------- | ---| Doc fix?      | no| New docs?     | yes (symfony/symfony#3465)| Applies to    | all| Fixed tickets |Commits-------57f467a add cookbook article for the server:run command
rande pushed a commit to sonata-project/sandbox that referenced this pull requestSep 24, 2014
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@michalpipa@sebhoerl@stof@jonathaningram@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp