1

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.

4
  • 3
    You'd want to specify an absolute path to that Feedlog.csv file. Under cron, a script's working directory will be the home directory of the user the script's running under, which is mostl likely NOT where the script file is located. If it was a permission error, you can check it by adding some error handling: if (!$fp2) { die ("Unable to open file"); } Commented Oct 3, 2011 at 18:21
  • 1
    Try using an absolute path to the file instead of relative. Commented Oct 3, 2011 at 18:21
  • I have a different thought, make sure the php binary /usr/bin/php is accessible via the crontab user Commented Oct 3, 2011 at 18:30
  • Hmm, this does make sense and I will try it in a moment, however, shouldn't this create an error if it could't open the file? I mean the script continues execution until its complete. Commented Oct 3, 2011 at 18:41

1 Answer 1

1

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.