douben8492
2011-10-03 18:19
浏览 62
已采纳

Cron Job没有通过PHP脚本运行

Firstly, I have built PHP scripts that run as a cron job when I set it up in linux and it works fine.

What I am doing in the script is writing to a file which isn't being done but works fine via CURL in terminal.

example (the first thing that happens in the script) :

#!/usr/bin/php
<?php
$fp2 = fopen('FeedLog.csv', 'w');

fputcsv($fp2,array("Started Cron",date("F j, Y, g:i a"),0));

I feel like there is some sort of permission issue? I have set both the script and the file its writing to, to 777.

There are no errors or anything in logs nor output.

图片转代码服务由CSDN问答提供 功能建议

首先,我在linux中设置了作为cron作业运行的PHP脚本,它工作正常 。

我在脚本中所做的是写入一个未完成的文件但通过终端中的CURL正常工作。

示例( 在脚本中发生的第一件事情:

 #!/ usr / bin / php 
&lt;?php 
 $ fp2 = fopen('FeedLog.csv',  'w'); 
 
ff以及($ fp2,数组(“已启动的Cron”,日期(“F j,Y,g​​:ia”),0)); 
   
  
 

我觉得有某种许可问题? 我已将脚本及其写入文件设置为777。

日志和输出中没有错误或任何内容。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmu3269 2011-10-03 18:28
    已采纳

    Either try a absolute path to the file in fopen, or use chdir to change to the correct directory.

    #!/usr/bin/php
    <?php
    chdir('/home/user/');
    $fp2 = fopen('FeedLog.csv', 'w');
    fputcsv($fp2,array("Started Cron",date("F j, Y, g:i a"),0));
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题