Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Hostgator cron作业无法使用此脚本_Php_Wordpress_Cron - Fatal编程技术网

Php Hostgator cron作业无法使用此脚本

Php Hostgator cron作业无法使用此脚本,php,wordpress,cron,Php,Wordpress,Cron,所以我一直在尝试使用Hostgator的Cron作业管理器,我选择php文件,它应该在调度时执行。如果我想手动运行脚本,那么我会编写并执行,在这种情况下,我会将PDF发送到电子邮件。请检查我的代码,看看我是否做错了什么: <?php define('WP_USE_THEMES', true); require( dirname( __FILE__ ) . '/wp-blog-header.php' ); set_time_limit(0); ignore_user_abort(1);

所以我一直在尝试使用Hostgator的Cron作业管理器,我选择php文件,它应该在调度时执行。如果我想手动运行脚本,那么我会编写并执行,在这种情况下,我会将PDF发送到电子邮件。请检查我的代码,看看我是否做错了什么:

<?php
define('WP_USE_THEMES', true);

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

set_time_limit(0);
ignore_user_abort(1);

$args = array(
        'post_type' => 'inversion',
        'orderby' => 'meta_value_num', 
        'meta_key' => 'numero_de_ordenamiento',
        'order' => 'ASC',
        'meta_query' => array(
            array(
                'key' => 'inversionista'
                )
            )
    );


    $the_query = new WP_Query( $args );
$current_posts = $the_query->get_posts();
print_r($current_posts);

foreach ($current_posts as $post)
{



        $post_id = $post->ID;
        $inversion = get_post($post_id);
        $eluser = get_field('inversionista',$post_id);
        $numconf=get_field('numero_de_cliente', 'user_'.$eluser['ID']);
        $numord = get_field('numero_de_ordenamiento',$post_id);

        ob_start(); ?>

        <section class="wrap">
            <img src="<?php bloginfo('template_directory');?>/images/CherryV.jpg" width="20%" alt="Site Logo">
            <img style="float:right;" src="<?php bloginfo('template_directory');?>/images/info.jpg" width="45%" alt="Site Logo">
        </section>

        <br>
        <a href="<?php echo wp_logout_url(); ?>">Logout</a>
        <br>
        <h3 style="color:red;"><u>Estado de movimientos <?php $month = date(m);
            if($month==1)
            {
                $elmes = "Enero";
            }elseif($month==2){
                $elmes = "Febrero";
            }elseif($month==3){
                $elmes = "Marzo";
            }elseif($month==4){
                $elmes = "Abril";
            }elseif($month==5){
                $elmes = "Mayo";
            }elseif($month==6){
                $elmes = "Junio";
            }elseif($month==7){
                $elmes = "Julio";
            }elseif($month==8){
                $elmes = "Agosto";
            }elseif($month==9){
                $elmes = "Septiembre";
            }elseif($month==10){
                $elmes = "Octubre";
            }elseif($month==11){
                $elmes = "Noviembre";
            }elseif($month==12){
                $elmes = "Diciembre";
            } 

            echo $elmes;
            echo " ";
            echo date(Y); ?></u></h3>

        <h3>Cliente confidencial: <?php echo $numconf; ?> </h3>

        <h3>Movimientos correspondientes al periodo: 1 al 31 de <?php echo $elmes ." ".date(Y); ?></h3>
        <br>

        <div id="customers">
            <table class="tabla" autosize="1" cellpadding="0" cellspacing="0" width="100%" border="1">
                <thead>
                <tr>
                    <td>
                        <h3 class="table2" >Periodo de Inversión</h3>
                    </td>
                    <td>
                        <h3 class="table2">Saldo Inicial</h3>
                    </td>
                    <td>
                        <h3 class="table2" >Inversión en el Periodo</h3>
                    </td>
                    <td>
                        <h3 class="table2" >Interés Causado en el Periodo</h3>
                    </td>
                    <td>
                        <h3 class="table2" >Intereses Pagados</h3>
                    </td>
                    <td>
                        <h3 class="table2" >Intereses Reinvertidos</h3>
                    </td>
                    <td>
                        <h3 class="table2" >Saldo Final</h3>
                    </td>
                </tr>
            </thead>
            <tbody>
            <?php
            $igalf = 0;
            if( have_rows('datos_especificos') ):
             ?>


                <?php
                $highest = 0;
                $arraycount=0; 
                $thearrayking = array();
                $arrayinsert = array();

                while ( have_rows('datos_especificos') ) : the_row();

                $icelpx = get_sub_field('interes_causado_en_el_periodo',$post_id);
                $cpx = get_sub_field('cantidad_pagada',$post_id);

                $crx = get_sub_field('cantidad_reinvertida',$post_id);

                $sal1x = get_sub_field('saldo',$post_id);
                $ipx = get_sub_field('inversion_en_el_periodo',$post_id);
                $sal2x = get_sub_field('saldo_final',$post_id);

                $fech = get_sub_field('fecha',$post_id);
                $fecharray0 = substr($fech,0,4);
                $fecharray1 = substr($fech,4,2);
                $fecharray = $fecharray1."/".$fecharray0;

                $sal1 = get_sub_field('saldo',$post_id);
                $ielp = get_sub_field('inversion_en_el_periodo',$post_id);
                $icelp = get_sub_field('interes_causado_en_el_periodo',$post_id);
                $cp = get_sub_field('cantidad_pagada',$post_id); 
                $elsf2 = get_sub_field('saldo_final',$post_id);
                $cr = get_sub_field('cantidad_reinvertida',$post_id);
                $crt = $crt+$cr;
                $sal2 = get_sub_field('saldo_final',$post_id);
                $igalf = $igalf+$icelp;
                $fech2 = $fech+100;
                $ID= $the_query->ID;

                if($highest<$elsf2)
                {
                    $highest = $elsf2;
                }



                $arrayinsert = array($fecharray, $elsf2);
                array_push($thearrayking, $arrayinsert);
                $arraycount = $arraycount+1;

                        $fechstring="$fech";
                        $part1=substr("$fechstring", 0, 4);
                        $part2=substr("$fechstring", 4, 2);
                        $part3=substr("$fechstring", 6,2);  

                    //$date = DateTime::createFromFormat('Ymd', $retrieved); ?>
                    <tr>
                        <td>
                            <p class="table" style="text-align:center;"> <?php echo $part3."/".$part2."/".$part1; ?> </p>
                        </td>
                        <td>
                            <p class="table" style="text-align:center;"> <?php echo "$ ".number_format($sal1,2); ?> </p>
                        </td>
                        <td>
                            <p class="table" style="text-align:center;"> <?php echo "$ ".number_format($ielp,2); ?> </p>
                        </td>
                        <td>
                            <p class="table" style="text-align:center;"> <?php echo "$ ".number_format($icelp,2); ?> </p>
                        </td>
                        <td>
                            <p class="table" style="text-align:center;"> <?php echo "$ ".number_format($cp,2); ?> </p>
                        </td>
                        <td>
                            <p class="table" style="text-align:center;"> <?php echo "$ ".number_format($crx,2); ?> </p>
                        </td>
                        <td>
                            <p class="table" style="text-align:center;"> <?php echo "$ ".number_format($sal2x,2); ?> </p>
                        </td>
                    </tr>
                     <?php
                endwhile;
            else :

                // no rows found

            endif;

            ?>
        </tbody>
            </table>
        </div>
        <br>
        <br>
        <h1>Resumen de Inversión</h1>
        <br>
        <table autosize="5">

               <?php 
                    $fech7 = $fech + 100;
                    $ptest = substr($fech7,4,2);

                    if($ptest==12)
                    {
                        $fech7=$fech7-1200+10000;
                    }

                    $fechstringxx = $fech7;

                    $part1x=substr("$fechstringxx", 0, 4);
                    $part2x=substr("$fechstringxx", 4, 2);
                    $part3x=substr("$fechstringxx", 6, 2); 

               //  $date2 = DateTime::createFromFormat('Ymd', $retrieved2); ?>
                <tr>
                    <td>
                        <h3 class="table2" style="text-align:center;"> Saldo Inicial <?php echo $part3."/".$part2."/".$part1; ?> </h3>
                    </td>
                    <td> 
                        <p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $sal1,2); ?> </p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h3 class="table2" style="text-align:center;"> Nuevas Inversiones </h3>
                    </td>
                    <td>
                        <p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $ielp,2); ?> </p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h3 class="table2" style="text-align:center;"> Intereses Pagados </h3>
                    </td>
                    <td>
                        <p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $cp,2); ?> </p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h3 class="table2" style="text-align:center;"> Intereses Reinvertidos </h3>
                    </td>
                    <td>
                        <p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $crx,2); ?> </p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h3 class="table2" style="text-align:center;"> Total Intereses Generados a la fecha</h3>
                    </td>
                    <td>
                        <p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $igalf,2); ?> </p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h3 class="table2" style="text-align:center;"> Saldo Final <?php echo $part3x."/".$part2x."/".$part1x; ?> </h3>
                    </td>
                    <td>
                        <p class="table" style="text-align:center;"> <?php echo "$ ".number_format( $sal2,2); ?> </p>
                    </td>
                </tr>
        </table>

        <?php $tableVar = ob_get_contents(); 

        $numord2 = str_replace(".","-",$numord);

        $correo = $current_user->user_email;
        // echo $correo;


          $mpdf = new mPDF('c');
            $stylesheet = file_get_contents(get_template_directory_uri() . '/table.css');
            $mpdf->WriteHTML($stylesheet,1);
            $mpdf->WriteHTML($tableVar,2);

            $mpdf->Output('test24.pdf','F'); 

        $content = $mpdf->Output('', 'S');

        $content = chunk_split(base64_encode($content));
        $mailto = $correo; //Mailto here
        $from_name = 'Cherry'; //Name of sender mail
        $from_mail = '9@gmail.com'; //Mailfrom here
        $subject = 'Reporte De Inversion'.$numord; 
        $message = 'Hola te mando tu reporte de inversion';
        $filename = "Reporte-De-Inversiones-".date("m-Y",time())." ".$numord2; //Your Filename whit local date and time

        //Headers of PDF and e-mail
        $boundary = "XYZ-" . date("dmYis") . "-ZYX"; 

        $header = "--$boundary\r\n"; 
        $header .= "Content-Transfer-Encoding: 8bits\r\n"; 
        $header .= "Content-Type: text/html; charset=ISO-8859-1\r\n\r\n"; //plain 
        $header .= "$message\r\n";
        $header .= "--$boundary\r\n";
        $header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
        $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n";
        $header .= "Content-Transfer-Encoding: base64\r\n\r\n";
        $header .= "$content\r\n"; 
        $header .= "--$boundary--\r\n";

        $header2 = "MIME-Version: 1.0\r\n";
        $header2 .= "From: ".$from_name." \r\n"; 
        $header2 .= "Return-Path: $from_mail\r\n";
        $header2 .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n";
        $header2 .= "$boundary\r\n";


        $bob = "bobsemail@email.com";

        //$sended = mail($mailto,$subject,$header,$header2, "-r".$from_mail);
        $sended2 = mail($bob,$subject,$header,$header2, "-r".$from_mail);
        //echo($sended);
        echo($sended2);
        $mpdf->Output($filename ,'F');

}


?>

/images/CherryV.jpg“width=“20%”alt=“Site Logo”>
/image/info.jpg“width=“45%”alt=“Site Logo”>


埃斯塔多·德·莫维门托斯酒店 客户保密: 相应的运动周期o:1 al 31 de
逆周期 萨尔多酒店 周期性反转 周期性因果关系 帕加多斯感兴趣 再抵押利息 萨尔多决赛



逆温简历
萨尔多酒店

努瓦斯倒转

帕加多斯感兴趣

再抵押利息

一般利息总额

萨尔多决赛


首先:Hostgator不允许cron在15分钟内运行,您可以读取该信息。如果这是你的情况,你的问题就解决了

现在有两种解决问题的方法:

1。修复cron并运行脚本(错误的或至少是错误的方式,我将在下面解释):

您需要授予文件的读写权限,以便系统可以运行它。请尝试777进行调试。 如果它不工作,请使用cron指令编辑OP,以便我们可以调试它

它的外观应该类似于下面的示例,Hostgator为您提供了有关其外观的信息:

Hostgator提供了关于cron和cURL的信息,有人在他们的论坛上抱怨同样的事情

在您的/home/文件夹的某个地方应该有一个名为cron.errors.log的文件,您肯定可以在那里找到相关信息

我很确定您的问题与include路径有关

我说这是不正确的方式,因为您使用的是Wordpress,在这种情况下,您应该使用本机WP核心功能,以使脚本正常工作,特别是通过执行插件和使用WP_schedule_event()

2。正确的方法-Plugin+wp_schedule_event()

将脚本转换为插件。通过这种方式,不需要包含wp-blog-header.php来访问函数,事情将更加集成

这里有一个关于如何做一个插件的例子,你可以在about it中访问关于wp_schedule_事件的信息

基本上,应该是这样的:

register_activation_hook( __FILE__, 'prefix_activation' );
/**
 * On activation, set a time, frequency and name of an action hook to be scheduled.
 */
function prefix_activation() {
    wp_schedule_event( time(), 'hourly', 'prefix_hourly_event_hook' );
}

add_action( 'prefix_hourly_event_hook', 'prefix_do_this_hourly' );
/**
 * On the scheduled action hook, run the function.
 */
function prefix_do_this_hourly() {
    // do something every hour
}
但有一个陷阱:只有当网站有访问者时,计划的活动才会运行。这不是最好的行为,而是我们现有的


通过这种方式,您将不再需要Hostgator,并且可以拥有一个与您的系统完美集成的酷炫插件。

只想留下一个提示,该脚本确实可以工作(当转到MyNameSite.com/myfile.php时),但在设置cronjob时它不能工作
register_activation_hook( __FILE__, 'prefix_activation' );
/**
 * On activation, set a time, frequency and name of an action hook to be scheduled.
 */
function prefix_activation() {
    wp_schedule_event( time(), 'hourly', 'prefix_hourly_event_hook' );
}

add_action( 'prefix_hourly_event_hook', 'prefix_do_this_hourly' );
/**
 * On the scheduled action hook, run the function.
 */
function prefix_do_this_hourly() {
    // do something every hour
}