虽然在PHP脚本中无法运行的循环在Crontab中运行

时间:2015-06-30 07:57:56

标签: php mysql crontab

我有一个php脚本作为crontab作业运行。

当我在浏览器中运行文件时,循环执行完美,但在crontab中运行时只执行第一次迭代而没有输出错误。

任何想法为什么?我完全难过!!!。

crontab条目:/ usr / bin / php /home/XXX/public_html/directory/cron/cron.php 2>& 1>> /home/XXX/public_html/directory/cron/script_output.log | mail -s“Cronjob PSTART Daily”me@XXX.com

PHP:

<?php
$members = new WA_MySQLi_RS("members", $alpha, 0);
$members->setQuery("SELECT

        registration.*,

        child_base_smqf.child_base_smqf_id,
        child_base_smqf.child_base_smqf_uid,
        child_base_smqf.child_base_smqf_open_timestamp,
        child_base_smqf.child_base_smqf_close_timestamp,

        parent_base_smqf.parent_base_smqf_id,
        parent_base_smqf.parent_base_smqf_uid,
        parent_base_smqf.parent_base_smqf_open_timestamp,
        parent_base_smqf.parent_base_smqf_close_timestamp

        FROM registration
        LEFT JOIN child_base_smqf ON registration.rego_parent_uid = child_base_smqf.child_base_smqf_uid
        LEFT JOIN parent_base_smqf ON registration.rego_parent_uid = parent_base_smqf.parent_base_smqf_uid

        WHERE
        registration.rego_parent_acc_status != 0 AND # NOT OPTED OUT
        child_base_smqf.child_base_smqf_close_timestamp IS NOT NULL AND # CHILD BASELINE SURVEY HAS BEEN COMPLETED
        parent_base_smqf.parent_base_smqf_close_timestamp IS NULL # PARENT BASELINE SURVEY HAS NOT BEEN COMPLETED

        GROUP BY `rego_parent_uid`
        ORDER BY `rego_id` ASC");

$members->execute();

while (!$members->atEnd()) {

// !DEFINE VARIABLES
    require('cronVariables.php');

    echo $members->getColumnVal("rego_parent_uid") . ' - ' .$members->getColumnVal("rego_parent_fname") . " STAMP - " . $members->getColumnVal("child_base_smqf_close_timestamp") . " baseline email reminders - " . $parent_base_surveyReminderTrigger . "<br>";

    require('parentBaseReminderEmails.php');

    $members->moveNext();
?>

2 个答案:

答案 0 :(得分:0)

从来没有深入到这个问题的底部,但通过curl运行url而不是直接从php运行php脚本来修复它:

/ usr / bin / curl -u uname:password --silent --compressed http://www.domain.net/dir/cron/cron.php

答案 1 :(得分:0)

在循环中使用“ require”而不是“ require_once”会导致致命错误,并在再次达到需求时终止于下一次迭代。

“致命错误:无法重新声明xyz”;

但这是一个猜测,却不知道这些“需要”位包含。

要使您免于沮丧,第一步是确保获得所有日志输出。

快速插入一行1,调试完成后删除,或者完成后将display_errors设置为0。

error_reporting(E_ALL);
ini_set('display_errors', 1);