swoole_framework应用服务器+nginx配置

swoole_framework框架的性能在使用nginx和php-fpm的时候并没有大的提升,如果使用app_server,据作者说性能较php-fpm有2倍的提升。

app_server.php使用官方例子:

<?php
define('DEBUG', 'on');
define("WEBPATH", realpath(__DIR__.'/../'));
require dirname(__DIR__) . '/libs/lib_config.php';

$server = Swoole\Network\Protocol\WebServer::create(__DIR__.'/swoole.ini');
$server->setAppPath(WEBPATH.'/apps/');                                 //设置应用所在的目录
$server->setDocumentRoot(WEBPATH);
$server->setLogger(new \Swoole\Log\EchoLog(__DIR__."/webserver.log")); //Logger
//$server->daemonize();                                                  //作为守护进程
$server->run(array('worker_num' => 1, 'max_request' => 5000, 'log_file' => '/tmp/swoole.log'));

重点来了,nginx配置:

location / {
        if (!-e $request_filename){
            proxy_pass http://127.0.0.1:8888;
       }
    }
location ~ .*\.(php|php5)?$  {
        proxy_pass http://127.0.0.1:8888;
#       fastcgi_pass 127.0.0.1:8888;
#       fastcgi_pass unix:/dev/shm/php-cgi.sock;
#       fastcgi_index index.php;
#       include fastcgi.conf;
        }

其实有了第一条配置就可以正常访问了(除了首页),增加第二条主要是为了访问首页。

标签: swoole_freamework, nginx, app_server

仅有一条评论

  1. 华尔街

    你好,我启动app_server的时候报了
    PHP Warning: cli_set_process_title(): cli_set_process_title had an error: Not initialized correctly in /Users/zhaoye/workspace/swooleframework/libs/Swoole/Console.php on line 57警告错误
    ,而且访问9501也没有反应,请问是不是我哪里有问题,还是我配置问题
    [request]
    default_page = "index.html"

    [server]
    host = "127.0.0.1"
    port = 9501
    max_request = 2000
    worker_num = 4
    webroot = 'http://127.0.0.1:9501'
    document_root = "/Users/zhaoye/workspace/swooleframework"
    process_rename = 1
    keepalive = 1
    gzip_open = 1
    user = www
    expire_open = 1

    [session]
    cookie_life = 1800
    session_life = 1800

    [access]
    deny_dir = "libs,class,templates"
    static_dir = "static/,"
    static_ext = "js,jpg,gif,png,css,html"
    dynamic_ext = "php"
    post_maxsize = 2000000

    [apps]
    charset = "utf-8"
    auto_reload = 1
    apps_path = "/Users/zhaoye/workspace/swooleframework/apps"
    ;是否处理静态文件
    do_static = on

添加新评论