使用 php 进行 cron 作业传递和检索变量


Cron Job Pass and Retrieve variables with php

我正在运行以下 cron 作业:

wget -q --spider --timeout=5 --tries=1 "http://www.publicvent.org/wow/kiwi/script.php" index=1

在脚本中.php我有:

require_once('functions-admin.php');
$argv = $_SERVER['argv'];
$index = $argv[1];
mail('email', 'Test', $index, '');

我也尝试使用:

require_once('functions-admin.php');
parse_str(argv[n]);
mail('email', 'Test', $index, '');

没有成功。

cron 作业运行良好,但$index中没有值。

任何帮助,不胜感激。谢谢。

您可以使用

$_GET

wget -q --spider --timeout=5 --tries=1 "http://www.publicvent.org/wow/kiwi/script.php?index=1"

在您的脚本中:

require_once('functions-admin.php');
$index = $_GET['index'];
mail('email@localhost', 'Test', $index, '');

问候!