douxiluan6555 2017-07-14 09:21
浏览 34
已采纳

Direct Admin上的Cronjobs无法正常工作

I created a cronjobs on direct admin, and if that running it will check curl =>>> change values in mysql. But it's not working. Please help me @@. Thanks This is my code:

    <?php

class ControllerVemaybayCronJobapp 
    {



            function index(){
            $connect = $this->connect();
            $query_routes_1 = $connect->query("SELECT * FROM **** where status = '0' GROUP BY routes ");
            for ($result = array();
            $row = $query_routes_1->fetch_assoc();
            $result[array_shift($row)] = $row);

            foreach ($result as $i => $aaa){
                $routes = $aaa['routes'];
                $detail_routes_2 = $connect->query("SELECT * FROM **** where routes = '" . $routes . "' AND status = '0' ");
                for ($result2 = array();
                $row2 = $detail_routes_2 ->fetch_assoc();
                $result2[array_shift($row2)] = $row2);

                foreach ($result2 as $t => $value1) {

                    $ngay = $value1['ngay'];
                    $thang = $value1['thang'];
                    $nam = $value1['nam'];
                    $min = $value1['minPrice'];
                    $max = $value1['maxPrice'];
                    $providers = $value1['providers'];
                    $startdate = $nam.$thang.'01';
                    $enddate = $nam.$thang.'31';

                    $bien = $this->getlist_ticketsofdate($routes,$startdate,$enddate);
                    foreach ($bien as $k => $value) {
                        $moi2 = array();
                        $moi = $value['c'];
                        $moi2 = $value['f'];
                        if($value['_id']['dim'] == $ngay ){
                            if($min <= $value['c'] && $value['c'] <= $max &&  strpos($providers, $value['p']) !== false){
                                $connect->query("UPDATE **** SET status='1' where customer_id = '" . $value1['customer_id'] . "' ");
                                break;
                            }else{
                                foreach ($moi2 as $key => $value2) {
                                    if($min <= $value2['cp'] && $value2['cp'] <= $max && strpos($providers, $value2['p']) !== false){
                                        $connect->query("UPDATE **** SET status='1' where customer_id = '" . $value1['customer_id'] . "' ") ;
                                         break;
                                    }
                                }
                            }
                        }
                    }
                 }
            }
        }


        function connect(){
            $servername = "****";
            $username = "****";  
            $password = "****";  
            $databasename = "****"; 
            $conn = new mysqli($servername, $username, $password,$databasename);
            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
            } 
            return $conn;
        }



        function getlist_ticketsofdate($diadiem,$startDate,$endDate){


            $url = '****';

            $providers = array();
            $providers[0] = '****';
            $providers[1] = '****';
            $providers[2] = '****';

            $routes = array();  
            $routes[0] = $diadiem;

            $headers = array();
            $headers[] = 'Content-Type: application/json';
            $headers[] = 'Connection:keep-alive';

            $param = array(
                'startDate' => $startDate,
                'endDate' => $endDate,
                'minPrice' => '0',
                'maxPrice' => '700000',
                'providers' => $providers,
                'routes' => $routes,
                'type' => 'date',
            );

            $data_string = json_encode($param);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);                                                                 
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);      
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            $response = curl_exec($ch);
            $result_tickets = json_decode($response,true);
            return $result_tickets;
        }
}
?>

This is my cronjobs

  • 写回答

1条回答 默认 最新

  • dsb53973 2017-07-14 09:37
    关注

    Cron job may not works directly on admin, cause it may required authentications for some process.

    Sample php file name mail.php

    <?php
    // the message
    $msg = "First line of text
    Second line of text";
    
    // use wordwrap() if lines are longer than 70 characters
    $msg = wordwrap($msg,70);
    
    // send email
    mail("someone@example.com","My subject",$msg);
    ?>
    

    Cron command:

    For url

    *   *   *   *   *   wget http://example.com/mail.php &> /dev/null
    

    For Path

    *   *   *   *   *   <BASE DIR>/mail.php
    

    This cron job send mail every minute.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动