简体   繁体   English

TYPO3 Scheduler什么都不做

[英]TYPO3 Scheduler does nothing

I've written a scheduler task. 我写了一个调度任务。 Its working fine on my maching. 在我的机器上工作正常。 Unfortunately its not working on my remote machine. 不幸的是,它不能在我的远程计算机上工作。

The machine is a freeBSD with php7.0 php-fpm running. 该机器是运行php7.0 php-fpm的freeBSD。 The cron looks like: Cron看起来像:

**MAILTO=mail@falk-roeder.de
@weekly /usr/local/bin/letsencrypt.sh -c
* * * * * php /var/www/alpha/beta/gamma/typo3/cli_dispatch.phpsh scheduler
#* * * * * php -r 'echo function_exists("foo") ? "yes" : "no";'

the last crontab is executed (if I comment it in) and mail output sent to me. 最后一个crontab被执行(如果我评论),并且邮件输出发送给我。

If I replace "scheduler" with something weird, I also get a mail with the output which contains the valid options I should choose. 如果将“ scheduler”替换为怪异的东西,我还会收到一封带有输出的邮件,其中包含我应该选择的有效选项。 So that means for me, that cron is running and the cli_dispatch.phpsh is called correctly. 因此,对我而言,这意味着cron正在运行,并且正确调用了cli_dispatch.phpsh。

In TYPO3 Backend the scheduler says the configuration is fine. 在TYPO3后端中,调度程序说配置很好。 I can manually start the cron and its doing the job. 我可以手动启动cron及其工作。

So, what else could the reason be...? 那么,还有什么原因呢?

EDIT 编辑

I figured out that the reason is, that the TYPO3 Scheduler didn't request the correct database. 我发现原因是TYPO3 Scheduler没有请求正确的数据库。 I've an AdditionalConfiguration file where the database name in $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] is changed based on the variable $_SERVER['SERVER_NAME']. 我有一个AdditionalConfiguration文件,其中基于变量$ _SERVER ['SERVER_NAME']更改了$ GLOBALS ['TYPO3_CONF_VARS'] ['DB'] ['database']中的数据库名称。 But in Scheduler this variable is empty. 但是在Scheduler中,此变量为空。 So I had to delete the AdditionalConfiguration file and everything is working as espected. 因此,我不得不删除AdditionalConfiguration文件,并且一切正常。

The question now is, how can I achieve Scheduler getting the right Database based on Servername? 现在的问题是,如何实现Scheduler基于Servername获取正确的数据库?

与其检查服务器变量,不如更好地使用应用程序上下文,该上下文也可以在调用调度程序时进行设置

For others more complete answer: 对于其他更完整的答案:

In .htaccess you set the Application Context of your site based on youtr hostname. 在.htaccess中,您可以根据youtr主机名设置站点的应用程序上下文。

Example: 例:

# Rules to set ApplicationContext based on hostname
RewriteCond %{HTTP_HOST} ^dev\.example\.de$
RewriteRule .? - [E=TYPO3_CONTEXT:Development]
RewriteCond %{HTTP_HOST} ^alpha\.example\.de$
RewriteRule .? - [E=TYPO3_CONTEXT:Production/Staging]
RewriteCond %{HTTP_HOST} ^www\.example\.de$
RewriteRule .? - [E=TYPO3_CONTEXT:Production]

In your AdditionalConfiguration.php you set the DB based on this Context. 在您的AdditionalConfiguration.php中,您将基于此上下文设置数据库。 Example: 例:

if (\TYPO3\CMS\Core\Utility\GeneralUtility::getApplicationContext()->isDevelopment()) {
    $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] = 'typo376_dev';
    $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] = 'typo376_dev_usr';
    $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] = 'somepw';
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] = '1';
} elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::getApplicationContext() == 'Production/Staging') {
    $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] = 'typo376_alpha';
    $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] = 'typo376_alpha_usr';
    $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] = 'someotherpw';
} else if(\TYPO3\CMS\Core\Utility\GeneralUtility::getApplicationContext() == 'Production') {
    $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] = 'typo376';
    $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] = 'typo376_usr';
    $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] = 'someotherpw';

} }

In your cron tab (edit it with crontab -e on your command line) you set the Envroiment Variable before you call the cliscript. 在cron选项卡中(在命令行上使用crontab -e对其进行编辑),您可以在调用气候脚本之前设置Envroiment变量。

Example: 例:

* * * * * TYPO3_CONTEXT=Production/Staging php /var/www/alpha/beta/gamma/typo3/cli_dispatch.phpsh scheduler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM