配置typo3/surf重置php opcache
一
配置opcache清除/重置脚本基本上需要四个步骤:
-
为设置任务选项
\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask
-
添加任务
\类型3\surf\task\php\webopcacheresetcreatescripttask
早期阶段(例如
package
但肯定是以前
transfer
)
-
为设置任务选项
\TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask
-
添加任务
\类型3\surf\task\php\webopcacheresetexecutetask
后阶段
switch
下面是oninitialize函数的必要片段
二
在部署配置脚本中:
为“创建脚本任务”设置任务选项:
因为“尊重网络目录”
patch
,脚本的路径不能手动配置,因为它会自动使用正确的webdirectory路径(该路径是通过选项beforhand设置的)。
如果您使用的是旧的Typo3/Surf版本或有任何特殊要求,可以设置选项
scriptBasePath
要设置结果文件的绝对路径,请执行以下操作:
# In this example, I have to set the absolute path for the resulting php file.
# Since the deployment run in GitLab CI I get the path to the root of the project's GIT
# repository via the environment variable `CI_PROJECT_DIR`. Since the path to the webDirectory
# inside the GIT repository is `<GitRepoRootFOlder>/app/web` I add it manually and concatenate
# it as final string for the option `scriptBasePath`:
$workflow->setTaskOptions(\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, [
'scriptBasePath' => \TYPO3\Flow\Utility\Files::concatenatePaths([getenv('CI_PROJECT_DIR'), '/app/web']),
]);
为“执行任务”设置任务选项:
此时,我们提供用户名和密码
$workflow->setTaskOptions('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask', [
'baseUrl' => $application->getOption('baseUrl'),
'stream_context' => [
'http' => [
'header' => 'Authorization: Basic '.base64_encode("username:password"),
],
],
]);
激活两个任务:
$workflow->beforeStage('transfer', \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, $application)
->afterStage('switch', \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask::class, $application);
此答案仅显示opcache重置过程所需的部分!
请同时检查
TYPO3 CMS deployment configuration example
在官方文件中。
脚注
一
这个答案基于typo3/surf git branch dev master版本2.x
二
将上述代码片段放置在何处的示例:
$deployment->onInitialize(function () use ($deployment, $application) {
/** @var SimpleWorkflow $workflow */
$workflow = $deployment->getWorkflow();
# the mentioned snippets have to be placed next to your existing configuration
});