如果您的网站每天有超过几百次的访问(太棒了!),等待Matomo处理您的数据可能需要几分钟。避免这些等待时间的最佳方法是在服务器上设置cron作业,以便每小时自动处理一次数据。

如果你正在使用Matomo WordPress,你不需要这样做,因为它利用WP Cron。如果你在Matomo云,这将自动为您照顾。

要自动触发Matomo存档,可以设置一个每小时执行一次的脚本

下面是关于Linux/Unix系统使用crontab,还可以用于指令窗户用户使用Windows任务调度器,以及工具,如CPanel.如果你不能访问服务器,你也可以设置一个web cron。

Linux/Unix:如何设置Crontab自动归档报表。

crontab是类unix服务器中基于时间的调度服务。crontab需要安装php-cli或php-cgi。您还需要通过SSH访问服务器来进行设置。让我们用文本编辑器创建一个新的crontab纳米

纳米/etc/cron.d/matomo-archive

然后添加这些行:

MAILTO="youremail@example.com" 5 * * * * www-data /usr/bin/php /path/to/matomo/console core:archive——url=http://example.org/matomo/ > /home/example/matomo-archive.log

Matomo存档脚本将每小时运行一次(在5分钟后)。一般在一分钟内完成。在较大的网站(10000次访问或更多),Matomo存档可能需要30分钟。

参数分解:

  • MAILTO =“youremail@example.com”如果在脚本执行过程中出现错误,脚本输出和错误消息将被发送到youremail@example.com地址。
  • www-data执行cron作业的用户。用户有时是“apache”。建议您以与web服务器用户相同的用户运行crontab(以避免文件权限不匹配).
  • /usr/bin/php是PHP可执行文件的路径。这取决于您的服务器配置和操作系统。您可以在linux shell中执行命令“which php”或“which php”,以查找php可执行文件的路径。如果您不知道路径,请询问您的web主机或系统管理员。
  • /路径/ / matomo /控制台是到你的服务器上的Matomo应用程序的路径。例如,它可能是/var/www/matomo/console
  • ——url = http://example.org/matomo/是脚本中唯一需要的参数,必须设置为您的Matomo基础URL,例如。http://analytics.example.org/http://example.org/matomo/
  • > /home/example/matomo-archive.log脚本将写入输出的路径。可以将此路径替换为/ dev / null如果您不愿意记录最后Matomo cron输出的文本。脚本输出包含有用的信息,如哪些网站被存档,处理每个日期和网站需要多长时间,等等。这个日志文件应该写在web服务器之外的位置,这样人们就不能通过浏览器查看它(因为这个日志文件将包含一些关于您的Matomo安装的敏感信息)。你也可以替换>通过>>为了将脚本输出附加到日志文件中,而不是在每次运行时都覆盖它(但是我们建议您旋转这个日志文件或删除它,例如。每周一次)。
  • 2 > /home/example/matomo-archive-errors.log脚本将在其中写入错误消息的可选路径。如果从cron选项卡中省略了这一点,那么错误将通过电子邮件发送到您的MAILTO地址。如果您在crontab中写入此命令,则错误将记录在指定的错误日志文件中。这个日志文件应该写在web服务器之外的位置,这样人们就不能通过浏览器查看它(因为这个日志文件将包含一些关于您的Matomo安装的敏感信息)。

'的描述linux cron的用途:cron实用程序使用两种不同类型的配置文件:系统crontab和用户crontab。这两种格式之间唯一的区别是第六个字段。

  • 系统定时任务,第6个字段是运行命令的用户名。这使系统crontab能够以任何用户身份运行命令。
  • 在一个用户crontab,第六个字段是要运行的命令,所有命令以创建crontab的用户的身份运行;这是一个重要的安全特性。

如果你将crontab设置为用户crontab,你可以这样写:

5 * * * * /usr/bin/php /path/to/matomo/console core:archive——url=http://example.org/matomo/ > /dev/null

这个cron作业将在每小时5分触发日/周/月/年的归档过程。这将确保当您访问Matomo仪表板时,数据已被处理;Matomo加载很快。

测试cron命令

通过在shell中以crontab用户运行脚本,确保crontab能够实际工作:

Su www-data -s /bin/bash -c "/usr/bin/php /path/to/matomo/console core:archive——url=http://example.org/matomo/"

您应该看到脚本输出中有存档的网站列表,末尾的摘要说明没有错误。

同时启动多个存档器

如果你有多个网站,你可能会对并行运行多个存档程序感兴趣,以便更快地存档。我们建议不要同时启动它们,而是每隔几秒或几分钟启动它们,以避免并发问题。例如:

5 * * * * /usr/bin/php /path/to/matomo/console core:archive——url=http://example.org/matomo/ > /dev/null 6 * * * * /usr/bin/php /path/to/matomo/console core:archive——url=http://example.org/matomo/ > /dev/null

在上面的例子中,一个存档器将在每小时的第5分钟启动,另一个将在一分钟后启动。或者,你也可以使用一个脚本同时启动多个存档程序,然后通过cronjob定期执行这个脚本。

CONCURRENT_ARCHIVERS=2 for i in $(seq 1 $CONCURRENT_ARCHIVERS) do (sleep $i && /path/to/matomo/console core:archive &) done

Windows:如何设置自动归档使用Windows调度器

->请参阅我们的专门的FAQ用于在Windows中设置计划任务

如何使用Plesk设置Cron脚本

了解更多关于在Plesk和安装Matomo的信息在Plesk Matomo指南中配置归档crontab。

如何使用CPanel设置Cron脚本

如果你使用用户界面,如CPanel, Webmin或Plesk,设置自动存档是很容易的。下面是CPanel的使用说明:

  1. 登录到安装了Matomo的域的CPanel
  2. 点击“Cron Jobs”
  3. 电子邮件空着
  4. 在“分钟”中输入00,其余的空着。
  5. 然后需要粘贴到PHP可执行文件的路径,然后是Matomo /console脚本的路径,然后是带有Matomo基本URL的参数url = matomo.example.org/
    下面是一个安装Hostgator的例子(在这个例子中,你需要将“yourcpanelsitename”更改为你特定的域cpanel用户名)

    /usr/local/bin/php -f /home/yourcpanelsitename/public_html/matomo/console core:archive——url=example.org/matomo/ > /home/example/matomo-archive-output.log

" yourcpanelsitename "往往是你的域名的前八个字母(除非你在设置你的cpanel帐户时改变了它)
6.点击“添加新的Cron作业”

Matomo将在整点自动处理您的报告。

当您的Web主机不支持Cron任务时,Web Cron

如果可能,我们强烈建议您运行cron或计划任务。但是,在某些共享主机上,或在特定的服务器配置上,运行cron或计划任务可能不容易或不可能。

一些网络主机允许你设置一个web cron,这是一个简单的URL,主机将在预定的时间自动访问它。如果你的虚拟主机允许你创建一个web cron,你可以在他们的主机界面中输入以下URL:

https://matomo.your-server.example/path/to/matomo/misc/cron/archive.php?token_auth=XYZ

用超级用户32个字符token_auth替换XYZ。要找到token_auth,请在Matomo中以超级用户身份登录,单击顶部菜单中的Administration链接,然后单击左侧的API链接,token_auth就会显示在页面上。

注:

  • 为了安全起见,如果可能的话,我们推荐您帖子将token_auth参数设置为URLhttps://matomo.your-server.example/path/to/matomo/misc/cron/archive.php(而不是发送token_auth作为得到参数)
  • 您可以通过将URL粘贴到浏览器中来测试web cron,等待几分钟处理完成,然后检查输出。
  • web cron应至少每小时触发一次。您也可以使用“网站监控”服务(免费或付费)每小时自动请求此页面。

中高流量网站的重要提示

禁用Matomo存档的浏览器触发器,并限制Matomo报告每小时更新一次

在像上面解释的那样设置了自动存档脚本之后,您可以设置Matomo,这样用户界面中的请求就不会触发存档,而是读取预存档的报告。以超级用户身份登录,单击管理>系统>常规设置,并选择:

  • 从浏览器查看存档报告:没有
  • 存档最多X秒上报一次:3600

单击save以保存更改。现在您已经设置了存档cron并更改了这两个设置,您可以在Matomo中享受快速预处理的接近实时的报告!

常规设置,上面的选项突出显示

今天的统计数据将有一个小时的生命周期,这确保报告每小时(大约)处理一次实时

增加PHP内存限制

如果你收到这个错误:

致命错误:允许的内存大小为16777216字节已耗尽(试图分配X字节)

您必须增加分配给PHP的内存。为了给Matomo足够的内存来处理您的web分析报告,将内存限制增加到512M:

memory_limit = 512M

去找你在哪里php . ini文件在您的服务器上,您可以按照以下步骤test.php文件并添加以下代码:

<?php phpinfo ();? >

然后在浏览器中打开它,它会显示运行在你的web服务器上的PHP正在读取的文件。它还将显示您的当前设置max_execution_time价值。

更多高流量服务器提示!

使用Matomo每月可以跟踪数百或数千个网站上的数百万个页面。一旦您像上面解释的那样设置了cron存档,还有其他重要而简单的步骤来提高Matomo性能。

有关更多信息,请参见如何配置Matomo的速度

关于Matomo存档的更多信息

  • 如果您每天运行存档几次,它将重新存档今天的报告,以及包括今天在内的日期范围内的任何报告:当前周、当前月等。
  • 您的Matomo数据库大小将随着时间的推移而增长,这是正常的。Matomo将删除处理不完整时期的存档(即当您在本周中存档一个星期时),但不会删除其他存档。这意味着您将在MySQL表中拥有每天、每周、每月和每年的存档。这确保了非常快速的UI响应和数据访问,但需要磁盘空间。
  • Matomo归档今天的报告并不是递增的:每天运行几次存档不会降低几周、几个月或每年归档的内存需求。Matomo将读取全天的所有日志,以处理当天的报告。
  • 一旦一天/周/月/年完成并被处理,它将被缓存,而不会被Matomo重新处理。
  • 如果您没有将存档设置为自动运行,则当用户请求Matomo报告时将发生存档。这可能会很慢,并提供糟糕的用户体验(用户将不得不等待N秒)。这就是为什么我们建议您设置自动归档中大型网站(点击查看更多信息)如上所述。
  • 默认情况下,当您禁用Matomo归档的浏览器触发器时,它不会像您所期望的那样完全禁用归档触发器。浏览Matomo的用户仍然能够在一种特定情况下触发档案处理:当一个自定义部分使用。为了确保Matomo的用户永远不会触发任何数据处理,在config.ini.php文件中,必须在(通用)类别:

    ;禁用所有请求的浏览器触发存档(即使是带有段的请求)browser_archiiving_disabled_enforce = 1

core的帮助:archive命令

下面是该命令的帮助输出:

$ ./console help core:archive用法:core:archive[——url="…""][——skip-idsites[= "…"[——skip-all-segments][——force-idsites[="…"“]]——skip-segments-today[-力-时间[=“……”]][——force-date-last-n[= "……"]][——force-date-range[= "…”]][——force-idsegments =“…"][——concurrent-requests-per-website[= "…"]][——concurrent-archivers[= "……“]]——max-websites-to-process = "…"][——max-archives-to-process = "……"][——disable- scheduling -tasks][——accept-invalid-ssl-certificate][——php-cli-options[="…"[——force-all-websites][——force-report[="…"选项:——url强制使用该选项的值作为Matomo的url。如果您的系统不支持使用CLI进程进行归档,则可能需要设置此选项,以便归档的HTTP请求使用所需的url。——skip-idsites如果指定了,这些网站的存档将被跳过(以防这些网站id已经被存档)。 --skip-all-segments If specified, all segments will be skipped during archiving. --force-idsites If specified, archiving will be processed only for these Sites Ids (comma separated) --skip-segments-today If specified, segments will be only archived for yesterday, but not today. If the segment was created or changed recently, then it will still be archived for today and the setting will be ignored for this segment. --force-periods If specified, archiving will be processed only for these Periods (comma separated eg. day,week,month,year,range) --force-date-last-n Deprecated. Please use the "process_new_segments_from" INI configuration option instead. --force-date-range If specified, archiving will be processed only for periods included in this date range. Format: YYYY-MM-DD,YYYY-MM-DD --force-idsegments If specified, only these segments will be processed (if the segment should be applied to a site in the first place). Specify stored segment IDs, not the segments themselves, eg, 1,2,3. Note: if identical segments exist w/ different IDs, they will both be skipped, even if you only supply one ID. --concurrent-requests-per-website When processing a website and its segments, number of requests to process in parallel (default: 3) --concurrent-archivers The number of max archivers to run in parallel. Depending on how you start the archiver as a cronjob, you may need to double the amount of archivers allowed if the same process appears twice in the `ps ex` output. (default: false) --max-websites-to-process Maximum number of websites to process during a single execution of the archiver. Can be used to limit the process lifetime e.g. to avoid increasing memory usage. --max-archives-to-process Maximum number of archives to process during a single execution of the archiver. Can be used to limit the process lifetime e.g. to avoid increasing memory usage. --disable-scheduled-tasks Skips executing Scheduled tasks (sending scheduled reports, db optimization, etc.). --accept-invalid-ssl-certificate It is _NOT_ recommended to use this argument. Instead, you should use a valid SSL certificate! It can be useful if you specified --url=https://... or if you are using Matomo with force_ssl=1 --php-cli-options Forwards the PHP configuration options to the PHP CLI command. For example "-d memory_limit=8G". Note: These options are only applied if the archiver actually uses CLI and not HTTP. (default: "") --force-all-websites Force archiving all websites. --force-report If specified, only processes invalidations for a specific report in a specific plugin. Value must be in the format of "MyPlugin.myReport". --help (-h) Display this help message --quiet (-q) Do not output any message --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version (-V) Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output --no-interaction (-n) Do not ask any interactive question --matomo-domain Matomo URL (protocol and domain) eg. "http://matomo.example.org" --xhprof Enable profiling with XHProf Help: * It is recommended to run the script without any option. * This script should be executed every hour via crontab, or as a daemon. * You can also run it via http:// by specifying the Super User &token_auth=XYZ as a parameter ('Web Cron'), but it is recommended to run it via command line/CLI instead. * If you have any suggestion about this script, please let the team know at feedback@m.hju8.com * Enjoy!

理解核心:存档输出

核心:存档输出日志显示有关存档进程的有用信息,特别是哪些网站和段正在被处理。输出特别显示:

  • 当前存档的网站ID:INFO[2020-03-31 21:16:29]将对网站id = 1,周期=月,日期= last3进行预处理
  • 这个网站有多少细分市场,在这个例子中有25个细分市场:INFO[2020-03-31 21:16:29] 23146 -预处理段1/25 countryName!——阿尔及利亚,2022年3月29日
  • 这个存档器的网站队列中还有多少网站需要处理,在这个例子中,它已经完成了3个网站中的2个:INFO[2020-03-31 21:17:07] 23146存档的网站id = 3,4 API请求,时间流逝:18.622s[2/3完成]
  • 如果你运行多个核心:存档流程使用——concurrent-archivers你可以通过查看时间戳后面的数字来区分不同的并发归档器:信息[2020-03-31 21:17:07]23146[…].每个不同的并发归档程序运行都有不同的编号。因此,如果您在您的日志中grep这个数字,您可以找到这个特定的核心:存档线程的输出。你也可以设置——concurrent-archivers-1这表明无限并发归档器。

如果您有任何问题或反馈,请使用下面的反馈按钮,我们将尽最大努力回复您。

下一个常见问题有视频解释如何安装Matomo吗?
以前的常见问题安装Matomo On-Premis亚博账号每天2000元出租e
Baidu