添加php脚本在cron中从php计划任务? [英] add php script in cron for scheduled task from php?

查看:453
本文介绍了添加php脚本在cron中从php计划任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以在cron中添加一个php脚本(文件),每10分钟或在预定时间运行此脚本?

is there a way to add a php script (file) in cron for running this script every ten minutes or at a scheduled time?

因为我想让用户以便能够安排何时发送通讯给他选择的很多电子邮件。

cause i want the user to be able to schedule when to send newsletter to a lot of emails he choses.

所以我必须从PHP创建一个cron作业,以运行一个php文件

so i have to create a cron job from php to run a php file on that scheduled time.

推荐答案

如果您的脚本文件名是news.php和/home/user/news.php
crontab行似乎是:

If you script filename is news.php and in /home/user/news.php crontab line seems like to be:

* * * * * php /home/user/news.php

如果你不想在每分钟运行这个。
您可以从左(m,h,dom,mon,dow)编辑*

If you want dont run this in every minute. You can edit * with from left (m, h, dom, mon, dow)

但是如果只有你web主机,
您必须具有访问shell或其他方式配置
您的crobtab文件(也许从您的提供程序访问面板)

But you cant do this if only you have same web hosting, you must have access to shell or other way to configure your crobtab file (maybe from your provider access panel)

但您可以在其他服务器上运行crontab作业以通过Apache协议运行您的news.php 。在此选项中,远程服务器上的crontab作业必须通过Web运行脚本。例如。 wget是一个很好的选择:

But you can run crontab job on other server to run your news.php by the apache over http protocol. In this option your crontab job on remote server must run your script by the web. Eg. wget is a good option for it:

* * * * * wget http://www.yourdomain.com/dir/news.php

这篇关于添加php脚本在cron中从php计划任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆