开发文档 v2.x

入口文件

更新时间:2024年4月1日 08:44 浏览:625

普通 php 模式下的入口文件(/www/index.php):

<?php
// 使用软链接外挂 www 目录时,使用 $_SERVER['DOCUMENT_ROOT'] 获取
// $rootPath =  dirname($_SERVER['DOCUMENT_ROOT']);
$rootPath = dirname(__DIR__);
$loader = require($rootPath . '/vendor/autoload.php');
$loader->addPsr4('Be\\Data\\', $rootPath . '/data');

$runtime = new \Be\Runtime\Driver\Common();
$runtime->setRootPath($rootPath);
\Be\Be::setRuntime($runtime);
$runtime->execute();

Swoole 模式下的入口文件(/server.php):

<?php
$loader = require(__DIR__ . '/vendor/autoload.php');
$loader->addPsr4('Be\\Data\\', __DIR__ . '/data');

$runtime = new \Be\Runtime\Driver\Swoole();
$runtime->setRootPath(__DIR__);
\Be\Be::setRuntime($runtime);
$runtime->execute();

 

两者的主要区别就是,实例化了不同的 Runtime 运行时 

  • 普通PHP模式:  \Be\Runtime\Driver\Common
  • Swoole模式:  \Be\Runtime\Driver\Swoole

通过两个不同的运行时,将框架隔离为完全独立的两套驱动,

 

导航