Create a cron job with user define dtime

2019-09-04 22:57发布

I want to create a cron job which will run with the user define time in database. For eg.User can set start time and end time in the database .When the end time is reached I want cron to trigger one script to send mail.First of all Is it possible in cron or I have to go with some different approach ? and this all things will be done on AWS EBS. Below is what I tried on my local machine to just send a simple mail which is too basic

*/1 * * * * /usr/bin/php -q/var/www/html/cronTry/cron.php

2条回答
闹够了就滚
2楼-- · 2019-09-04 23:20

You dont want to run the CRON every minute instead create a specific job for your user and run it once. Something like this should work (untested - on mobile)

$your_users_date;
$cmd = "sudo crontab -l | { cat; echo ". date("i H d m",strtotime($your_users_date))." * php /path_to_your_script.php arg1 arg2; } | crontab -";
shell_exec($cmd);

This will append a job to the crontab at the time your user has defined

查看更多
我想做一个坏孩纸
3楼-- · 2019-09-04 23:35

Get the dynamic details from the database, create the command string and

You can easily run your cron by passing the command in the shell_exec()

查看更多
登录 后发表回答