Answer the question
In order to leave comments, you need to log in
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
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
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);
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question