【问题标题】:command not found error on cronjob in php在 php 中的 cronjob 上找不到命令错误
【发布时间】:2020-10-26 15:50:23
【问题描述】:

我已经设置了一个 cron 作业命令来自动增加通过 API 发布的金额

 0 0 * * * /usr/bin/php -f /home/wmglobal/public_html/admin/congtienbaohiem.php > /dev/null

以及带有此代码的 congtienbaohiem.php

$db = mysqli_connect('localhost', 'wmglobal_lixin', 'wmglobal_lixin', 'wmglobal_lixin');
$query = "SELECT * FROM baohiem where trangthai='1'";
$result= $db->query($query);
if ($result->num_rows > 0) {
    while($row = $result ->fetch_assoc()) {
        $sotien = $row['sotien'];
        $username = $row['username'];
        $id = $row['id'];
        $loituc = $sotien * 0.1 /100;

        $gmusername = '789'.$username;
        $gmpassword = $passwordmd5;
        $externalTransactionId = 'WM555BLOBAL'. $id;
        $params=[
                'username'=> $gmusername,
                'amount'=> $loituc,
                'externalTransactionId'=> $externalTransactionId
            ];
        $curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL => "https://api.gmaster8.com/WM/credit/deposit",
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $params,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => array(
        "Authorization: Basic Nzg5QVBJOjEyMzQ1Njc4OTA="
        ),
        CURLOPT_USERPWD => "$gmusername:$gmpassword",
        ));
        curl_exec($curl);
    }
}

但是发送到我邮箱的结果是

/usr/local/cpanel/bin/jailshell: 0: command not found

我不知道如何解决这个问题,请帮忙。

【问题讨论】:

  • 良好的代码缩进将帮助我们阅读代码,更重要的是,它将帮助您调试代码Take a quick look at a coding standard 为您自己的利益。您可能会被要求在几周/几个月内修改此代码,最后您会感谢我的。

标签: php api cron-task


【解决方案1】:

我已经通过将 cron 作业命令更改为来解决这个问题

wget http://www.wm555.global/admin/congtienbaohiem.php

并将成功的结果发送到邮箱

--2020-07-06 14:08:02--  http://xxxxxxxx/admin/congtienbaohiem.php
Resolving www.wm555.global... xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx, 104.18.63.120, ...
Connecting to xxxxxxx|104.18.62.120|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “congtienbaohiem.php”
0K                                                        25.8M=0s

2020-07-06 14:08:03 (25.8 MB/s) - “congtienbaohiem.php” saved [83]

【讨论】:

    猜你喜欢
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    相关资源
    最近更新 更多