Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

php - How to schedule notification

So I have a database that I query from to check if the date on there is equals to today's date. Is there a way I can run this PHP script without visiting this page to check if there is any date that is equals to the todays date and send FCM notification? Below is example of what am looking at:


<?php
$todaydate = date("Y-m-d");

$query = "select * from TABLE where date = $todaydate";
$result = mysqli_query($db, $query);
if(mysqli_num_rows($result) > 0){

...sending FCM notification      

}

?>

I know cronjob can do this but don't know how to use on to achieve this.

question from:https://stackoverflow.com/questions/66054660/how-to-schedule-notification

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can just run the script (for example) every 12 hours.

You can either do this with the Linux command crontab -e for the currently logged-in user or you can edit /etc/crontab to run the script as a specific user.

With crontab -e your line would look like this:

0 */12 * * * php /path/to/script.php >/dev/null 2>&1

As I said, in /etc/crontab you can specify a specific user. It would look like this:

0 */12 * * * username php /path/to/script.php >/dev/null 2>&1

username can be something like www-data. Just make sure the specified user has read/execute permissions on the script's file.

>/dev/null 2>&1 means that the output of the command is muted. You could also write the output into a file. There are also crontab-generators.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...