In general, the situation is this. There is a script that can work in some rare cases longer than the interval in a cronjob, but you need to run it every minute, since in 95% of cases it works in a few seconds. It is necessary to exclude the possibility of re-launch. Immediately make a reservation, this is free hosting, so there is no SSH access, and it is impossible to monitor processes. It remains only to implement this using PHP
Tried so
//Π‘ΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΉ ΡΠ°ΠΉΠ» ΠΊΠΎΡΠΎΡΡΠΉ Π±ΡΠ΄Π΅Ρ Ρ
ΡΠ°Π½ΠΈΡΡ ΠΈΠΌΡ Π²ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠ³ΠΎ ΡΠ°ΠΉΠ»Π° $lockFilename = __DIR__ . '/lock.dat'; //ΠΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ ΡΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ Π»ΠΈ Π²ΡΠ΅ΠΌΠ΅Π½Π½ΡΠΉ ΡΠ°ΠΉΠ» if (file_exists($lockFilename) && ($lock = file_get_contents($lockFilename)) && file_exists($lock)) { echo "Cron running now {$lock}\n"; exit(); } //Π€Π°ΠΉΠ» Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠΌΠ΅ΡΠ΅ΡΡ ΠΏΡΠΈ Π·Π°ΠΊΡΡΡΠΈΠΈ Π΄Π΅ΡΠΊΡΠΈΠΏΡΠΎΡΠ° $tmpHandle = tmpfile(); //ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΈΠΌΡ Π²ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠ³ΠΎ ΡΠ°ΠΉΠ»Π° $metaData = stream_get_meta_data($tmpHandle); //ΠΠ°ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ ΠΈΠΌΡ Π²ΡΠ΅ΠΌΠ΅Π½Π½ΠΎΠ³ΠΎ ΡΠ°ΠΉΠ»Π° Π² ΡΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΉ ΡΠ°ΠΉΠ» file_put_contents($lockFilename, $metaData['uri']); //Cron ΡΠΈΠΌΡΠ»ΡΡΠΈΡ echo "Cron started\n"; sleep(20); echo "Cron stopped\n"; exit(); But the file remains, if you terminate the script via Ctrl + C
I thought to solve the problem through memcache and the lifetime of the key, but the free hosting doesnβt provide memcache
The file is automatically removed when closed (for example, by calling fclose(), or when there are no remaining references to the file handle returned by tmpfile()), or when the script ends.If you create a file using WinApi CreateFile and theFILE_FLAG_DELETE_ON_CLOSEflag, even if you kill the process on the fly, the file will be deleted. Apparently everything is different in PHP and Linux ((( - Ninazu