XML API 在 cPanel 中创建 cron 任务

XML API to create cron tasks in cPanel

我正在尝试使用 xmlapi php 创建 cron 任务。我可以使用 php API 创建 cron 任务,但是当我使用“*”时它不起作用。 这是我的代码

$xmlapi = new xmlapi("123.456.7.8");
$xmlapi->password_auth(user, pass);
$xmlapi->set_debug(1);
$command = "php -q /home/user/public_html/reports/set_cron.php";
$day = '0';
$hour = '*';
$minute = '*';
$month = '*';
$weekday = '*';
$set = $xmlapi->api2_query($account, "Cron", "add_line", array(
    "command"       => $command,
    "day"           => $day,
    "hour"          => $hour,
    "minute"        => $minute,
    "month"         => $month,
    "weekday"       => $weekday
));

使用它我必须能够创建一个每小时 运行 的 cron 任务。但这给了我错误

SimpleXMLElement Object
(
    [apiversion] => 2
    [data] => SimpleXMLElement Object
        (
            [linekey] => 3502285593
            [status] => 0
            [statusmsg] => "-":14: bad day-of-month
errors in crontab file, can't install.

        )

    [error] => "-":14: bad day-of-month
errors in crontab file, can't install.

    [event] => SimpleXMLElement Object
        (
            [result] => 1
        )

    [func] => add_line
    [module] => Cron
)

如果我使用它,它会起作用

$day = '1';
$hour = '1';
$minute = '1';
$month = '1';
$weekday = '1';

我想将 cron 设置为每小时 运行。我该怎么做?

每小时的 cron 频率设置为 0 * * * *,因此您可以使用:

$set = $xmlapi->api2_query($account, "Cron", "add_line", array(
    "command"       => $command,
    "day"           => '*',
    "hour"          => '*',
    "minute"        => '0',
    "month"         => '*',
    "weekday"       => '*'
));