Log non JSON API responses
This commit is contained in:
@@ -32,6 +32,14 @@ function unav_read_only(): bool {
|
||||
return getenv('U_NAV_READ_ONLY') === '1';
|
||||
}
|
||||
|
||||
function unav_function_available(string $name): bool {
|
||||
if (!function_exists($name)) {
|
||||
return false;
|
||||
}
|
||||
$disabled = array_map('trim', explode(',', (string)ini_get('disable_functions')));
|
||||
return !in_array($name, $disabled, true);
|
||||
}
|
||||
|
||||
function unav_json($payload, int $status = 200): void {
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
@@ -35,11 +35,22 @@ unav_job_write($job);
|
||||
|
||||
$worker = __DIR__ . '/job_worker.php';
|
||||
$php = is_executable('/usr/bin/php') ? '/usr/bin/php' : (PHP_BINARY ?: 'php');
|
||||
if (function_exists('exec') && is_file($worker)) {
|
||||
exec(escapeshellarg($php) . ' ' . escapeshellarg($worker) . ' ' . escapeshellarg($id) . ' > /dev/null 2>&1 &');
|
||||
} else {
|
||||
require $worker;
|
||||
$started = false;
|
||||
|
||||
if (unav_function_available('exec') && is_file($worker)) {
|
||||
try {
|
||||
$exitCode = 0;
|
||||
@exec(escapeshellarg($php) . ' ' . escapeshellarg($worker) . ' ' . escapeshellarg($id) . ' > /dev/null 2>&1 &', $output, $exitCode);
|
||||
$started = ($exitCode === 0);
|
||||
} catch (Throwable $error) {
|
||||
$started = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$started) {
|
||||
require_once $worker;
|
||||
unav_run_job($id);
|
||||
$job = unav_job_read($id);
|
||||
}
|
||||
|
||||
unav_json($job, 202);
|
||||
|
||||
Reference in New Issue
Block a user