php - while 循环在 php 中不起作用 脚本在 Crontab 中运行

标签 php mysql cron

我有一个 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 |邮件-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();
?>

最佳答案

从未深入了解这个问题,但通过curl运行url而不是直接从php运行php脚本来修复它:

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

关于php - while 循环在 php 中不起作用 脚本在 Crontab 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31132677/

相关文章:

mysql - 为什么 documentdb 查询返回未定义或空值的数据?

mysql - 将查询语句和结果保存到mysql中

ruby-on-rails - 创建每周/每月/每日排行榜

Mysqldump 无法在 FreeBSD 中使用动态文件名与 cron 作业一起工作

php - 使用其他表中的 id 查询以获取最新的 10 行

php - 拉拉维尔 5.5 : php artisan tinker : ErrorException : Directory not empty

mysql - 在mysql中的多个表中获取不同的月份名称并计算重复值

php - 使用 php 在一定时间后删除文件的 cronjob 格式是什么?

php - 在 HTTPS 响应的正文中返回一个 JSON 对象

php - Nginx fastcgi_index index.php 不工作