问题描述
我想创建一个cron作业,该作业将与用户在数据库中定义时间一起运行。
例如,用户可以在数据库中设置开始时间和结束时间。到达结束时间时,我希望cron触发一个脚本发送邮件。首先是cron是否可能,否则我必须一些不同的方法?所有这些都将在AWS EBS上完成。
以下是我在本地计算机上尝试发送的太简单的邮件
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
推荐答案
您不想每分钟运行CRON,而是为您的用户创建一个特定的作业,然后运行一次。像这样的东西应该起作用(未经测试-在移动设备上)
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);
这将在用户定义时将作业添加到crontab中
This will append a job to the crontab at the time your user has defined
这篇关于使用用户定义dtime创建cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!