-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCronSync.php.example
More file actions
36 lines (32 loc) · 1.37 KB
/
CronSync.php.example
File metadata and controls
36 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* This file configures synchronization via cron instead of the default lazy approach.
* Using cron-based synchronization is recommended for websites with high traffic.
*
* When using this mode, pass `'sync_by_cron' => true` when instantiating
* the CleanTalkAntiCrawler class. This disables the built-in lazy synchronization logic.
*
* Copy this file into your project and adjust it to your needs.
* Then configure your system cron to execute this file periodically
* (for example, every 5 minutes).
*/
// Cron line example: */5 * * * * yourusername php /path/to/file/CronSync.php
// Make sure you run cronjob as the same user that owns the database!
/** Edit this path depending on where in your project you're going to put the file */
require_once __DIR__ . "/vendor/autoload.php";
use Cleantalk\PHPAntiCrawler\Settings;
use Cleantalk\PHPAntiCrawler\SQLiteManager;
use Cleantalk\PHPAntiCrawler\SyncManager;
Settings::configure([
'api_key' => 'put_your_key_here',
'db_path' => '/tmp/anticrawler.sqlite',
'visitor_forget_after' => 60 * 60 * 24 * 30,
// 'requests_backend' => 'keydb',
// 'keydb_host' => '127.0.0.1',
// 'keydb_port' => 6379,
// 'keydb_database' => 0,
// 'keydb_password' => '',
// 'keydb_prefix' => 'anticrawler',
]);
$pdo = SQLiteManager::initDb(Settings::$dbPath);
(new SyncManager($pdo))->syncByCron(Settings::$apiKey);