首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在cPanel中设置PHP CRON作业?

如何在cPanel中设置PHP CRON作业?
EN

Stack Overflow用户
提问于 2019-05-03 13:50:29
回答 2查看 51关注 0票数 0

我已经在cpanel中添加了cronjob,以便在php中使用textloal发送短信。它在cronjob之外工作得很好。在cronjob中运行后,它不会发送任何sms。

这是我的代码

代码语言:javascript
复制
<?php 
include('dbc.php');

error_reporting(E_ALL); ini_set('display_errors', 1);
require('php-in/textlocal.class.php');
//require('php-in\Textlocal.class.php');

//require('consultantnext.com/danceschool/php-in/Textlocal.class.php');
$sql="SELECT * 
    FROM admin t1, batchinfo t2
    WHERE t1.batchname= t2.batchname  
    AND   t1.branchname= t2.branchname";

$result= mysqli_query($conn,$sql)
or die($sql."<br/><br/>".mysql_error());

if (mysqli_num_rows($result)>0) {
    while($row=mysqli_fetch_array($result)) {

        //echo   $row['mobile'];
        $mobile=$row['mobile'];
        $time=$row['time'];
        //echo $time;
        $numbers=(explode(" ",$mobile));
        foreach ($numbers as $item) {
            echo $item;
        }

        $Textlocal = new Textlocal(false, false, 'e34FsEpkeUo-
   uLJ17oDYeEgHBucRHTnNtHhrE39Pj4');

        //$numbers = array(919384191234,918056377914);
        $sender = 'TXTLCL';
        $message = "Dear student your class schedule for tomorrow '$time'";

        $response = $Textlocal->sendSms($numbers, $message, $sender);
        print_r($response);
        //echo $message;
    }
}


$sql="SELECT   * FROM admin
    WHERE username NOT IN (
    SELECT studentname 
    FROM transcation  
    WHERE MONTH(DATE(date))=MONTH(CURDATE())  
    ) 
    and usertype='student'   ";

$result= mysqli_query($conn, $sql)
or die($sql."<br/><br/>".mysql_error());
If(mysqli_num_rows($result)>0) {

    while($row=mysqli_fetch_array($result)) {
        $username=$row['username'];
        echo $username;
        $mobile=$row['mobile'];

        $numbers=(explode(" ",$mobile));
        foreach ($numbers as $item) {
            echo $item;
        }

        $Textlocal = new Textlocal(false, false, 'e34FsEpkeUo-
uLJ17oDYeEgHBucRHTnNtHhrE39Pj4');

        $sender = 'TXTLCL';
        $message = "Dear student please pay the fees before due date.  ";

        $response = $Textlocal->sendSms($numbers, $message, $sender);
        print_r($response);

    }
}

这是我的命令:

代码语言:javascript
复制
/usr/local/bin/php /home/cpdarmkr/public_html/danceschool/message.php   
EN

回答 2

Stack Overflow用户

发布于 2019-05-03 13:54:56

问题可能不在于您的代码,而在于您的命令。也许可以试试这个命令,它可能会起作用:

代码语言:javascript
复制
* * * * *  /usr/bin/php -q /home/cpdarmkr/public_html/danceschool/message.php
票数 0
EN

Stack Overflow用户

发布于 2019-05-03 14:09:49

这对我很有效

使用cURL:

代码语言:javascript
复制
  */5 * * * * curl --silent http://your-website-url/danceschool/message.php
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55963936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档