Symfony的 标准发行版只支持一个站点,虽然可以通过路由系统中的 Host配置,根据不同的域名使用不同的路由规则,这样也可以实现类似多站点的功能,但缺点也非常明显:
symfony
- 如果希望某个Service在不同的站点有不同的表现,就没办法实现(DI不能直接注入Request)。
- 静态文件没办法很好拆分开来
- 每个页面请求都需要加载所有站点的配置(bundle、路由规则、Service等等),影响性能
经过搜索,发现也有人有相同的困惑,也给出了一个初步的 解决方案。但是还是有一些细节方面的问题,比如标准发行版自带的Composer post-install-cmd/post-update-cmd(清文件缓存、生成bootstrap.cache.php、发布静态文件到web根目录等)不能正常使用。那篇文章只是通过软链解决了bootstrap.cache.php的问题,但并没有提到清文件缓存等。
leo108's blog
这个问题只能自己写代码来解决了,新建一个composer项目,依赖于sensio/distribution-bundle,新建一个ScriptHandler类,代码如下:
http://leo108.com/pid-2202.asp
namespace Dreamore\DreamoreBundle\Composer;use Composer\Script\CommandEvent;use Sensio\Bundle\DistributionBundle\Composer\ScriptHandler as Base;class ScriptHandler extends Base{ /** * Composer variables are declared static so that an event could update * a composer.json and set new options, making them immediately available * to forthcoming listeners. */ protected static $options = array( 'dm-apps' => array(), 'dm-assets-install' => 'hard', 'dm-cache-warmup' => false, ); /** * Builds the bootstrap file. * * The bootstrap file contains PHP file that are always needed by the application. * It speeds up the application bootstrapping. * * @param $event CommandEvent A instance */ public static function buildBootstrap(CommandEvent $event) { $options = static::getOptions($event); foreach ($options['dm-apps'] as $config) { $bootstrapDir = $config['app-dir']; $autoloadDir = $config['autoload-dir']; if (!static::hasDirectory($event, 'app-dir', $bootstrapDir, 'build bootstrap file')) { return; } if (!static::hasDirectory($event, 'autoload-dir', $autoloadDir, 'build bootstrap file')) { return; } static::executeBuildBootstrap($event, $bootstrapDir, $autoloadDir, $options['process-timeout']); } } /** * Clears the Symfony cache. * * @param $event CommandEvent A instance */ public static function clearCache(CommandEvent $event) { $options = static::getOptions($event); foreach ($options['dm-apps'] as $config) { $consoleDir = $config['app-dir']; if (!static::hasDirectory($event, 'app-dir', $consoleDir, 'execute command')) { return; } $warmup = ''; if (!$options['dm-cache-warmup']) { $warmup = ' --no-warmup'; } static::executeCommand($event, $consoleDir, 'cache:clear'.$warmup, $options['process-timeout']); } } /** * Installs the assets under the web root directory. * * For better interoperability, assets are copied instead of symlinked by default. * * Even if symlinks work on Windows, this is only true on Windows Vista and later, * but then, only when running the console with admin rights or when disabling the * strict user permission checks (which can be done on Windows 7 but not on Windows * Vista). * * @param $event CommandEvent A instance */ public static function installAssets(CommandEvent $event) { $options = static::getOptions($event); foreach ($options['dm-apps'] as $config) { $needAssets = isset($config['need-assets']) ? $config['need-assets'] : true; if (!$needAssets) { continue; } $consoleDir = $config['app-dir']; if (!static::hasDirectory($event, 'app-dir', $consoleDir, 'execute command')) { return; } $webDir = $config['web-dir']; $symlink = ''; if ($options['dm-assets-install'] == 'symlink') { $symlink = '--symlink '; } elseif ($options['dm-assets-install'] == 'relative') { $symlink = '--symlink --relative '; } if (!static::hasDirectory($event, 'web-dir', $webDir, 'install assets')) { return; } static::executeCommand($event, $consoleDir, 'assets:install '.$symlink.escapeshellarg($webDir), $options['process-timeout']); } } protected static function getOptions(CommandEvent $event) { $options = array_merge(static::$options, $event->getComposer()->getPackage()->getExtra()); $options['process-timeout'] = $event->getComposer()->getConfig()->get('process-timeout'); return $options; }}
这里就重写buildBootstrap\clearCache\installAssets这三个方法的逻辑,同时为了避免冲突,我重新命名了配置项,composer.json的配置如下: symfony
"autoload": { "psr-4": { "": "src/" }, "files": [ "apps/api/ApiKernel.php", "apps/admin/AdminKernel.php", "apps/wap/WapKernel.php" ]},"scripts": { "post-install-cmd": [ "Dreamore\\DreamoreBundle\\Composer\\ScriptHandler::buildBootstrap", "Dreamore\\DreamoreBundle\\Composer\\ScriptHandler::clearCache", "Dreamore\\DreamoreBundle\\Composer\\ScriptHandler::installAssets" ], "post-update-cmd": [ "Dreamore\\DreamoreBundle\\Composer\\ScriptHandler::buildBootstrap", "Dreamore\\DreamoreBundle\\Composer\\ScriptHandler::clearCache", "Dreamore\\DreamoreBundle\\Composer\\ScriptHandler::installAssets" ]},"extra": { "dm-apps": [ { "app-dir": "apps/api", "autoload-dir": "apps", "need-assets": false }, { "app-dir": "apps/admin", "autoload-dir": "apps", "web-dir": "web/admin" }, { "app-dir": "apps/wap", "autoload-dir": "apps", "web-dir": "web/wap" } ], "dm-assets-install": "relative"}
autoload中的file加入各个站点的kernel文件,这样就不需要手动require了。 leo108's blog
scripts替换成我们自己的ScriptHandler
推酷是个无耻的网站
dm-apps是一个数组,每个站点一项,每个站点的配置有app-dir、autoload-dir、web-dir、need-assets,app-dir代表kernel文件所在的目录;autoload-dir代表autoload.php文件所在的目录,由于各个站点的autoload.php完全一致,所以我就把这个文件放到apps目录下,所有站点共享(因此需要修改每个站点的app.php app_dev.php和console这3个文件);web-dir代表发布静态文件的目标目录;need-assets代表是否需要发布静态文件(比如api这个站点就不需要发布静态文件)。

로드 밸런싱은 세션 관리에 영향을 미치지 만 세션 복제, 세션 끈적임 및 중앙 집중식 세션 스토리지로 해결할 수 있습니다. 1. 세션 복제 복사 서버 간의 세션 데이터. 2. 세션 끈은 사용자 요청을 동일한 서버로 안내합니다. 3. 중앙 집중식 세션 스토리지는 Redis와 같은 독립 서버를 사용하여 세션 데이터를 저장하여 데이터 공유를 보장합니다.

SessionLockingIsateChniqueSureDureauser의 SessionLockingSsessionRemainSexclusivetoOneuseratatime.itiscrucialforpreptingdatacorruptionandsecurityBreachesInmulti-userApplications.sessionLockingSogingSompletEdusingserVerver-sidelockingMegynisms, unrasprantlockinj

PHP 세션의 대안에는 쿠키, 토큰 기반 인증, 데이터베이스 기반 세션 및 Redis/Memcached가 포함됩니다. 1. Cookies는 클라이언트에 데이터를 저장하여 세션을 관리합니다. 이는 단순하지만 보안이 적습니다. 2. Token 기반 인증은 토큰을 사용하여 사용자를 확인합니다. 이는 매우 안전하지만 추가 논리가 필요합니다. 3. Database 기반 세션은 데이터베이스에 데이터를 저장하여 확장 성이 좋지만 성능에 영향을 줄 수 있습니다. 4. Redis/Memcached는 분산 캐시를 사용하여 성능 및 확장 성을 향상하지만 추가 일치가 필요합니다.

SessionHijacking은 사용자의 SessionID를 얻음으로써 사용자를 가장하는 공격자를 말합니다. 예방 방법은 다음과 같습니다. 1) HTTPS를 사용한 의사 소통 암호화; 2) SessionID의 출처를 확인; 3) 보안 세션 생성 알고리즘 사용; 4) 정기적으로 SessionID를 업데이트합니다.

이 기사는 PHP에 대해 설명하고, 전체 형식, 웹 개발의 주요 용도, Python 및 Java와의 비교 및 초보자를위한 학습 용이성을 자세히 설명합니다.

PHP는 유효성 검사, 소독 및 보안 데이터베이스 상호 작용을 통해 보안을 보장하면서 $ \ _ post 및 $ \ _를 사용하여 데이터 양식 데이터를 처리합니다.

이 기사는 PHP와 ASP.NET을 비교하여 대규모 웹 응용 프로그램, 성능 차이 및 보안 기능에 대한 적합성에 중점을 둡니다. 둘 다 대규모 프로젝트에서는 실용적이지만 PHP는 오픈 소스 및 플랫폼 독립적이며 ASP.NET,

PHP의 사례 감도는 다양합니다. 함수는 무감각하고 변수와 클래스는 민감합니다. 모범 사례에는 일관된 이름 지정 및 비교를위한 사례 감수 기능 사용이 포함됩니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

Dreamweaver Mac版
시각적 웹 개발 도구

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구
