What are CRON JOBS and how do you use them with PHP [duplicate]

2

Recently I asked this question , but I found it kind of vulnerable to use the codes that were answered, summarizing the best answer: Create a Cookie with a Time and hide the button, after this time runs out, the button returns. (If some cheeky wipe the cookies it can use the system again).

I'd like to do the same with Cron but so far I do not understand what they are, and how do you use them to run a script every now and then, taking a look here in the OS, I found

asked by anonymous 01.08.2017 / 09:45

2 answers

7

Cron is a task scheduler present on Unix systems. It just does this: schedule tasks to run at regular intervals.

In response to your question they gave you this code:

59 23 * * * php -f /home/u844214382/cronjobs/nomedoarquivo.php

It can be translated as:

  

Every day, at 23 hours, at minute 59 , run the

     

php -f /home/u844214382/cronjobs/nomedoarquivo.php

You can see how to create these and other combinations of commands using this site: link

Cron is a generic system tool. The unique relationship of it with PHP is due to the fact that it is capable of firing scripts on the system, so you can use it to run PHP scripts on the command line too, as the example indicates.

To use a metaphor:

  

Cron is an alarm clock. In the interval you send it will play and   poking his script at him to wake up. From here the script will turn   alone to accomplish the tasks that have to be done.

So the questions you ask from 1 to 5 can be resolved in pure PHP, taking into account that it will run on the command line (not a request from a browser), with Cron only as a scheduler and trigger of the tasks.

    
01.08.2017 / 14:04
4

Cron jobs does not have anything to do with your problem, setting a cron job on the server, it simply causes a particular script to run every%% time.

This validation of time, can only be done in the client or be X , to have a control on this would be necessary, a column in the bank with value javascript for the button, and a column of type booleano , comparing the time the button was triggered and the time the user entered the page again.

Another alternative would be to limit time in Date , but it would not be as accurate, until seq sessão consume of your server, so why consume in several places, if it can consume only one? Session Time

Remember that you are treating multiple users on a particular page, you will have to have control under each one individually.

    
01.08.2017 / 14:23