swoole http 서버는 phalcon, ab 테스트를 통합하고 PHP 메모리가 고갈되었음을 보고합니다.

WBOY
풀어 주다: 2016-09-08 08:29:39
원래의
1431명이 탐색했습니다.

在整合swoole http server和phalcon,server.php如下:

<code><?php

use Phalcon\DI;
use Phalcon\Loader;
use Phalcon\Mvc\Router;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Http\Response;
use Phalcon\Http\Request;
use Phalcon\Mvc\View;
use Phalcon\Db\Adapter\Pdo\Mysql as Database;
use Phalcon\Mvc\Application as BaseApplication;
use Phalcon\Mvc\Model\Metadata\Memory as MemoryMetaData;
use Phalcon\Mvc\Model\Manager as ModelsManager;

class Application extends BaseApplication
{

    protected function registerAutoloaders()
    {

        $loader = new Loader();

        $loader->registerDirs(array(
            '../apps/controllers/',
            '../apps/models/'
        ));

        $loader->register();
    }

    /**
     * This methods registers the services to be used by the application
     */
    protected function registerServices()
    {

        $di = new DI();

        //Registering a router
        $di->set('router', function(){
            return new Router();
        });

        //Registering a dispatcher
        $di->set('dispatcher', function(){
            return new Dispatcher();
        });

        //Registering a Http\Response
        $di->set('response', function(){
            return new Response();
        });

        //Registering a Http\Request
        $di->set('request', function(){
            return new Request();
        });

        //Registering the view component
        $di->set('view', function(){
            $view = new View();
            $view->setViewsDir('../apps/views/');
            return $view;
        });

        $di->set('db', function(){
            return new Database(array(
                "host" => "localhost",
                "username" => "root",
                "password" => "",
                "dbname" => "invo"
            ));
        });

        //Registering the Models-Metadata
        $di->set('modelsMetadata', function(){
            return new MemoryMetaData();
        });

        //Registering the Models Manager
        $di->set('modelsManager', function(){
            return new ModelsManager();
        });

        $this->setDI($di);
    }

    public function main()
    {
        $this->registerServices();
        $this->registerAutoloaders();
    }
}

$application = null;

$http = new swoole_http_server("0.0.0.0", 9501);

$http->on('request', function ($request, $response) {
    try {
        $_GET = $_POST = $_COOKIE = $_REQUEST = [];

        if (!empty($request->get)) {
            $_GET = $request->get;
            $_REQUEST += $_GET;
        }

        if (!empty($request->post)) {
            $_POST = $request->post;
            $_REQUEST += $_POST;
        }

        if (!empty($request->cookie)) {
            $_COOKIE = $request->cookie;
        }

        global $application;
        $html = $application->handle($request->server['request_uri'])->getContent();
        $response->end($html);
    } catch (\Exception $e){
        print_r($e);
        echo $e->getMessage();
    }
});

$http->on('WorkerStart', function($server, $workerId) {
    global $application;
    $application = new Application();
    $application->main();
});
# 启动服务器
$http->start();</code>
로그인 후 복사

浏览器访问没什么问题
做ab测试就报错了

<code>ab -n 10000 -c 1000 -rk http://phalcon.com/</code>
로그인 후 복사

错误信息:

<code>[root@localhost public]# [2016-08-25 17:12:45 *12502.0]    ERROR    zm_deactivate_swoole (ERROR 103): Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 16384 bytes) in /srv/www/single/public/server.php on line 126.
[2016-08-25 17:12:45 $12497.0]    WARNING    swManager_check_exit_status: worker#0 abnormal exit, status=255, signal=0</code>
로그인 후 복사

请教这是什么原因导致的,是onRequest那里写的不对吗?

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!