【问题标题】:file_put_contents does not work properly in cron jobfile_put_contents 在 cron 作业中无法正常工作
【发布时间】:2014-03-03 21:33:08
【问题描述】:

我有一个 cron 作业运行每 1 分钟 向手机发送推送消息。

1.我在数据库中执行 fetch 查询以获取我需要发送的所有消息

2.使用该数组中的数据,我执行另一个获取查询。 我使用 file_put_contents 将数据写入某个文件。

3.然后我使用一些服务发送推送消息。

消息已成功接收,但数据未写入文件(我在第二点这样做)。

注意:当我在本地机器上手动运行此文件时,此代码运行完美。

我发现了什么

有人建议我你的 mysql 执行查询速度很慢,因此之前执行了其他脚本行,因此出现错误。

代码

    Sone database query that will give customer ids in $customer_ids array

    $customer_ids = array_unique($customer_ids);
    foreach ($customer_ids as $customer_id){
        //Problem is here.file is written here using file_put_contents (this does not work-file does not update)
        PushMessage_Model_Mapper_PushMessage::getPublishfile($customer_id);
    }
    foreach ($customer_ids as $customer_id){
        //push messages are send by calling some function
    }

此类行为是否存在任何已知问题。

【问题讨论】:

    标签: php mysql cron


    【解决方案1】:

    验证执行 cronjob 的用户是否可以写入文件。

    【讨论】:

    • 是的,它拥有所有权限。我们尝试通过 cron 作业将虚拟数据记录到文件中。
    • 将 cronjob 的输出记录在一个文件中,可能脚本会抛出错误
    猜你喜欢
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    相关资源
    最近更新 更多