How to schedule time-based tasks (Cron) using PHP ?

Asked

Viewed 362 times

0

I am developing a module in the shop, and need to schedule some tasks based on time. For example : On day X perform the function Y of my module.

Is there a way to interact with the prestashhop cronjob module ? There is another solution to this ? I’m densevolving in PHP, a javascript solution would also be valid.

  • @rray I am not using Linux.

  • 2

    Prestashop’s cron module only works with linux natively. In windows it only works when being accessed after scheduling (the system checks whether past the date on access, and performs the tasks in positive case).

1 answer

1

So, PHP is a language that only collects and processes the data providing a result, so it doesn’t have native cron functions and you shouldn’t even try to cheat it out of it. (That is, it processes the data it has to process and dies soon after)

Good, now your operating system is different, it can create check a file regularly(crontab) and perform certain instruction as it is specified.

Exemplifying:

# [Quando vai rodar] [Comando que vai rodar]
  * 1 * * * php      /var/www/site/public/index.php --module=z --action=y

That is, I specified that the command "/var/www/site/public/index.php --module=z --action=y" will run every day at 1 hr.

Finally, the configuration can change according to the operating system, so I recommend that you learn the concept (https://en.wikipedia.org/wiki/Cron) a cron, and apply as per your system.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.