概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:42:49 | 112 次阅读 | 评论: 0 | 来源: 网络整理

2.6 新版功能: The ability to run the server as a background process was introduced in Symfony 2.6.

Since PHP 5.4 the CLI SAPI comes with a built-in web server. It can be used to run your PHP applications locally during development, for testing or for application demonstrations. This way, you don’t have to bother configuring a full-featured web server such as Apache or Nginx.

警告

The built-in web server is meant to be run in a controlled environment. It is not designed to be used on public networks.

Starting the Web Server

Running a Symfony application using PHP’s built-in web server is as easy as executing the server:start command:

$ php app/console server:start

This starts the web server at localhost:8000 in the background that serves your Symfony application.

By default, the web server listens on port 8000 on the loopback device. You can change the socket passing an IP address and a port as a command-line argument:

$ php app/console server:run 192.168.0.1:8080

注解

You can use the server:status command to check if a web server is listening on a certain socket:

$ php app/console server:status

$ php app/console server:status 192.168.0.1:8080

The first command shows if your Symfony application will be server through localhost:8000, the second one does the same for 192.168.0.1:8080.

注解

Before Symfony 2.6, the server:run command was used to start the built-in web server. This command is still available and behaves slightly different. Instead of starting the server in the background, it will block the current terminal until you terminate it (this is usually done by pressing Ctrl and C).

Command Options

The built-in web server expects a “router” script (read about the “router” script on php.net) as an argument. Symfony already passes such a router script when the command is executed in the prod or in the dev environment. Use the --router option in any other environment or to use another router script:

$ php app/console server:start --env=test --router=app/config/router_test.php

If your application’s document root differs from the standard directory layout, you have to pass the correct location using the --docroot option:

$ php app/console server:start --docroot=public_html

Stopping the Server

When you are finished, you can simply stop the web server using the server:stop command:

$ php app/console server:stop

Like with the start command, if you omit the socket information, Symfony will stop the web server bound to localhost:8000. Just pass the socket information when the web server listens to another IP address or to another port:

$ php app/console server:stop 192.168.0.1:8080
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务