简体   繁体   English

在cron作业中,file_put_contents无法正常工作

[英]file_put_contents does not work properly in cron job

I have a cron job running every 1 minute to send push messages to mobile phones. 我有一个计划任务, 每1分钟运行一次,以将推送消息发送到手机。

1.I perform fetch query in database to get all messages that I need to send 1.我在数据库中执行获取查询以获取所有需要发送的消息

2.With the data in that array I perform another fetch query. 2.使用该数组中的数据,我执行另一个提取查询。 I use file_put_contents to write data to some file . 我使用file_put_contents将数据写入某个文件

3.Then I send push messages using some services. 3.然后我使用某些服务发送推送消息。

Message is successfully received but data is not written in file (that I do in second point). 消息已成功接收,但数据未写入文件中 (我在第二点中做了)。

Note: This code runs perfectly when I manually run this file on my local machine. 注意:当我在本地计算机上手动运行此文件时,此代码可以完美运行。

What I found 我发现了什么

Someone suggested me that your mysql is performing queries slow and so other lines of scripts are executed before and so the error. 有人建议我,您的mysql执行查询的速度很慢,因此之前执行了其他几行脚本,因此出现错误。

The Code 编码

    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
    }

Are there any known issues for such behavior. 是否存在此类行为的任何已知问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM