Such a task, you need to force one script to work on the site after a certain time, it is desirable that it was js, or that it was php that runs the js code. How to implement correctly? I want the script to work every hour. I emphasize that it is important that the js script is not dependent on the page from which it was launched. The logic is that php is launched from the page, which the user who ran the code or not on the site should not care. The script, for example, should constantly ping one domain and put all this in the logs. How to make php work constantly? So I went to the script settings page, set the interval, launched it and forgot, and it works.

I understand correctly that just throwing everything in while(true) will not help?

  • Use the command 'crontab -e' - Vlad Vetrov
  • In nodejs, this is an easy task. setTimeout functions, the interval for which you take from the cache (memcached / redis / regularfile). The page with an interval changes it. - vp_arth
  • @vp_arth, can I pull api for js using node.js? And as I understand it on a rented hosting, I will not have access to memcached / redis / regularfile? - Alexey Vladimirovich
  • one
    regularfile means just a file. You can not create a file? Then put it in the database. After all, keep this thing straight in the memory / variable nodejs. I have no idea what api for js means. nodejs is js. - vp_arth
  • @vp_arth, understood, thanks, I thought it was some kind of system file) I'll dig, thanks again - Alexey Vladimirovich

1 answer 1

Suppose so:

 set_time_limit(0); // неограниченное время выполнения скрипта ignore_user_abort(true); function task() { // Код задачи } while (true) { task(); $delay = file_get_contents('delay.cfg'); // период повтора в секундах sleep($delay); } 

Admin should edit the file delay.cfg

It is necessary to implement protection from the repeated launch of the script, to write the timestamp of the last iteration on semaphores or to a file, if too much time has passed, allow restarting.

The hoster has the ability to limit the maximum running time of scripts.