开发者

How can i use cron job in Social engine?

开发者 https://www.devze.com 2022-12-23 16:38 出处:网络
I am new with cron job in p开发者_Python百科hp,basically i want to send email to user on certain time of period.i want to send email daily,weekly,monthly,quarterly,yearly,or specific amount of days.

I am new with cron job in p开发者_Python百科hp,basically i want to send email to user on certain time of period.i want to send email daily,weekly,monthly,quarterly,yearly,or specific amount of days.

In smarty template i want to use this type of function Can any body know how to do tihs?


CRON is based on the server. You can't run CRON jobs from within PHP. You have actually run it on the server. If you have shared hosting or something, you can usually set up CRON jobs via the administrative control panel or something similar.


It's possible to write to the webserver user's crontab from PHP, depending on security configuration.

$job = "* * * * * /bin/ls";
$p = popen("crontab -", "w");
$return = fwrite($p, $job, strlen($job));
pclose($p);

This will erase the contents of your existing crontab. You could read the existing job in first:

$p = popen("crontab -l", "r");
while ($crontab[] = fgets($p)) { /* ... */ }
pclose($p);

Then modify that as appropriate. You'll want your code to be idempotent so you can run it many times without worrying about what will happen.

Note that your host may not allow your PHP to do this, and even if it does, it may not be a good idea. As @Foo says, the best way is to just talk to cron directly. Get a shell session and run crontab -e, or see what you can do with whatever web interface you can get.

0

精彩评论

暂无评论...
验证码 换一张
取 消