1

I set up a cron job on my site with Hostinger that is supposed to scrape news contents and dump the information into a text file. This isn't what I want my cron output to be, but a byproduct of running the script.

If I simply wisit the webpage this is located at, I get a success. It correctly opens the file and writes the news data to it. When it's run by the cron job, however, I get the output

PHP Warning:  fopen(../txtdumps/newsdump.txt): failed to open stream: No such file or directory in /home/u189772133/public_html/cronjobs/newsscrape.php on line 12
Unable to open file

I've never done a cron job before, so is it just bad practice to open and write to files within one, or is this simply a pathing issue?

theupandup
  • 335
  • 3
  • 14
  • Probably a permissions issue. When you call it from the browser, the script is run as the same user your webserver (Apache, Nginx, etc.) is running as (most likely `www-data`). When run via cron, it's run as the user that owns the crontab (most likely `u189772133` given your home folder name). That user must also be able to write to the file. – rickdenhaan Sep 10 '17 at 15:36

1 Answers1

1

check that you have granted your PHP file access to write information to the hard drive.

also you may make sure you passed the mode to fopen

fopen("../txtdumps/newsdump.txt", "w")

you can check this for permissions issue

How do I give PHP write access to a directory?

Klamius
  • 167
  • 2
  • 10