0 votes
23 views

How to run the PHP Script automatically every 5 seconds between the time slots 13:00:00 to 14:00:00 and 16:00:00 to 17:00:00 everyday?

PHP Script :

<?php
$datetime = date("l jS \of F Y h:i:s A"); 
$apiToken = "1825671537:AAEYexjklpoiyUdEeG8Ml";
$telegram_chatid = '-10012345607';
$message = urlencode($datetime);
                
$telegram_call = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?chat_id=$telegram_chatid&parse_mode=markdown&text=$message");
exit();
?>

Source Author: Amlan Dutta

by (2.2k points)   | 23 views

1 Answer

0 votes

Well you can't do it with the cron job but you can use the cron job as an initiator.

This could be a way to solve this issue. you can run a cron job everyday at 13:00 o'clock.

Your script on the other hand should have a loop which sleeps 5 second and goes again through the loop. Once you reach 17:00 o'clock it will stop the loop and exit.

And there should be another check in the loop, which checks whether you are between the given time e.g. 13:00-14:00 or 16:00-17:00, if so it will run your script and sleep 5 seconds, if not it will just run the the loop

Another way would be to run a cron job every hour. And in your script you have to check it the hour is the one you want to start doing something. if so, you just do it like the above loop.

Credit to: litux

by (2.2k points)  

Related questions

+3 votes
1 answer
asked Apr 12, 2020 by athar (3.2k points) | 122 views
+2 votes
0 answers
0 votes
1 answer
0 votes
22 answers
asked May 13 by admin (2.2k points) | 219 views
+1 vote
1 answer
asked Oct 4, 2020 by toheed (1.4k points) | 104 views
+1 vote
1 answer
+3 votes
1 answer
asked Mar 30, 2020 by toheed (1.4k points) | 68 views
+4 votes
1 answer
asked Mar 29, 2020 by admin (2.2k points) | 115 views
+4 votes
1 answer
asked Mar 20, 2020 by Ron | 95 views
Welcome to Givemeans.net here you can ask questions and get the answers from other members of the community.
143 questions
123 answers
43 comments
159 users