Best place to keep files that are called by cron jobs?

I am interesting in setting up a Wordpress Website which needs to keep updating certain custom database tables after fetching data from RESTful Web Services, lets say once in a day.

I can achieve this by having a script to make request to REST API, process data and then store it into required tables.

However, I am not sure where to put this script file so cron can call it without any issues (security wise)

  • Can I place these script files at root level of wordpress directory (such as /script1.php, script2.php etc)?
  • Or I create a plugin of the script, would cron be able to access this file placed inside a plugins directory?

UPDATE

  1. There will be multiple scripts used by cron, therefore, I want to make plugins out of each script.. Would cron be table to access files in the plugins directory?

Anyone who can help?

Topic rest-api cron plugin-development Wordpress

Category Web


Assuming you're running cron jobs under your user account, it will have access to any folder that your account has read access to. If you do not need them to be publicly accessible, and you have access to a folder outside your public web root, then for security purposes you should put them outside of the web root.

However, if you are on shared hosting, this may not be possible due to open_basedir restrictions. In that case, you can either create a subdirectory under your main Wordpress directory, or in your plugins folder. You can add an htaccess file to block access from the outside.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.