35 lines
979 B
PHP
35 lines
979 B
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
header('Content-Type: text/plain; charset=UTF-8');
|
|
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
|
header('Pragma: no-cache');
|
|
|
|
// Log erreurs PHP (utile sans SSH)
|
|
ini_set('log_errors', '1');
|
|
ini_set('error_log', __DIR__ . '/webcron_error.log');
|
|
|
|
// ===== sécurité =====
|
|
const CRON_TOKEN = 'e3e6ba5785a447c3f763a4ca4b8c36480df63a19';
|
|
|
|
if (! hash_equals(CRON_TOKEN, $_GET['token'] ?? '')) {
|
|
http_response_code(403);
|
|
exit("forbidden\n");
|
|
}
|
|
|
|
// ===== anti double exécution =====
|
|
$lockFile = __DIR__ . '/cron.lock';
|
|
$lock = fopen($lockFile, 'c');
|
|
if (! $lock || ! flock($lock, LOCK_EX | LOCK_NB)) {
|
|
exit("already running\n");
|
|
}
|
|
|
|
// ===== log minimal =====
|
|
file_put_contents(__DIR__ . '/webcron.log', date('Y-m-d H:i:s') . " before worker\n", FILE_APPEND);
|
|
|
|
require __DIR__ . '/worker.php';
|
|
|
|
file_put_contents(__DIR__ . '/webcron.log', date('Y-m-d H:i:s') . " after worker\n", FILE_APPEND);
|
|
|
|
echo "OK\n";
|