S
S
soundie2021-12-22 23:52:47
PHP
soundie, 2021-12-22 23:52:47

Is it possible to set up a PHP script to run hourly without Cron and without changing the web server settings?

Is it possible to set up regular PHP script execution (for example, once an hour) without getting into the web server settings (increasing max_execution_time in PHP and the like), as well as in Cron?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Shumov, 2021-12-22
@soundie

Take an external cron service and pull the api according to the schedule. But it's cheaper and easier to rent a normal virtual machine

S
soundie, 2021-12-23
@soundie

Surprisingly, a simple idea worked - to restart the script through itself within a certain period of time, less than the limit set on the server. For example:

// test.php

<?php 

// max_execution_time на сервере равна 300 секунд (5 минут), 
// поэтому устанавливаем меньше - 240 секунд (4 минуты)
sleep(240);

// оставляем временнУю метку в файле или в БД
// проверяем - прошел ли час, затем обновляем её 

// перезапускаем сами себя
$url = 'https://site.ru/test.php';
$headers = []; // создаем заголовки
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$result = curl_exec($curl);

?>

That's the whole script. Launched once in the browser (did not wait, but closed the tab immediately). Then he restarts himself every 4 minutes and each time checks if an hour has passed. The test for an hour and a half showed that it works :) I'll let you know if something suddenly falls off later ...
UPDATE: I was happy early. I worked the script with restarts for 2 hours and then just took it and stopped restarting. Apparently some unknown gear in the web server is vigilant and closes this case...

S
sasmoney, 2021-12-23
@sasmoney

Take a dedik with Windows and leave the page running, create a page with a page update via js.
300-500r per month

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question