2014-11-26 1 views
0

저는 Cron Job Manager를 Hostgator에서 사용하려고 했으므로 php 파일을 선택 했으므로 일정이 잡히면 실행해야합니다. 스크립트를 수동으로 실행하려면 http://thesitename.com/myfile.php을 작성하고 실행합니다.이 경우 PDF를 전자 메일로 보냅니다. 모든 전에Hostgator cron 작업이이 스크립트로 작동하지 않습니다.

<?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 = '[email protected]'; //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 = "[email protected]"; 

     //$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'); 

} 


?> 
+0

이 스크립트는 작동합니다 (mynameamesite.com/myfile.php로 갈 때).하지만 cronjob을 설정할 때는 나던하지 않습니다. –

답변

0

: 내가 뭔가 잘못하고 있어요 경우 내 코드를 확인하고 참조하십시오 Hostgator이 15 분 미만의 차이로 실행 크론을 허용하지 않습니다, 당신은 그 정보 here를 읽을 수 있습니다. 그것이 사실이라면 문제는 해결됩니다.

지금이 문제 해결의 두 가지 방법 :

1. 수정 크론를하고 스크립트 실행 (적어도 잘못된 또는 잘못된 방법은, 내가 아래에 설명 할 것이다) :

시스템에서 실행할 수 있도록 파일에 대한 읽기 및 쓰기 권한을 부여해야합니다. 디버깅을 위해 777을 시도하십시오. 작동하지 않는 경우 cron 명령으로 OP를 편집하여 디버그하십시오.

/opt/php55/bin/php /home/username/public_html/cron.php 

Hostgator이는 컬을 here에 대해, 크론 here에 대한 정보를 제공하고 같은 일에 대해 불평하는 사람이있다 :

그것은 아래의 예와 같이 보일 것이다, Hostgator의는 here을 보일 것입니다 방법에 당신에게 정보를 제공 그들의 포럼 here.

/home/폴더의 어느 부분이 cron.errors.log 파일이어야합니다. 관련 정보를 찾을 수 있습니다.

나는 당신의 문제가 포함 경로와 관련 있다고 확신한다.

나는 특히 wp_schedule_event()

을 플러그인을하고 사용하여 스크립트 작업을 만들기 위해 당신이 워드 프레스를 사용하고 있고 그 경우에 당신이 순서대로 기본 WP의 핵심 기능을 사용해야하기 때문에 이것은 잘못된 방법이다라고 2. 올바른 방법 - Plugin + wp_schedule_event();

스크립트를 플러그인으로 변환하십시오. 이렇게하면 함수에 액세스하기 위해 wp-blog-header.php를 포함 할 필요가 없으며 훨씬 더 통합적으로 작동합니다.

플러그인을 수행하는 방법은 quick tutorial이고 여기에 대해서는 Wordpress page의 wp_schedule_event에 대한 정보에 액세스 할 수 있습니다.

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에서 벗어나 시스템과 완벽하게 통합 된 멋진 플러그인을 사용할 수 있습니다.

관련 문제