简体   繁体   English

加载php脚本以与cron一起运行

[英]Load php script to run with cron

First, apologize for my English. 首先,为我的英语道歉。

I am creating a script for my web subscription. 我正在为我的Web订阅创建脚本。 This script will run with a cron but I doubt emerges. 该脚本将与cron一起运行,但我怀疑会出现。

My host has a limit of 25 emails every 2 minutes, 200 emails per hour, and the php max_execution_time configuration is 120. The script should send 6 emails every minute. 我的主机每2分钟限制25封电子邮件,每小时限制200封电子邮件,并且php max_execution_time配置为120。脚本应每分钟发送6封电子邮件。 Because of this limutaciójn, I get the time it takes to run the script and do a sleep time to 1 minute remaining, so do not like to do is to reload the script with the new parameters sent using GET. 由于这种限制,我得到了运行脚本和将睡眠时间保留到剩下的1分钟所需的时间,所以不喜欢用使用GET发送的新参数重新加载脚本。

When a script run by cron, I can not use javascript or header location, so do not really know how to make this script will reload with the new parameters. 当脚本由cron运行时,我无法使用javascript或标头位置,因此不真正知道如何使此脚本将使用新参数重新加载。

Does anyone have any idea, please? 请问有人知道吗?

You can use cron to launch your PHP script via either command-line or with a workaround as a standard web script. 您可以使用cron通过命令行或作为标准Web脚本的替代方法来启动PHP脚本。 If you want the latter you can just wget http://localhost/whatever.php > /dev/null 2>&1 . 如果需要后者,则只需获取wget http://localhost/whatever.php > /dev/null 2>&1 Note the output redirection, because any output in processes lauched with cron will be mailed to the owner of the given crontab, so better suppress the output and log errors or notification separately. 请注意输出重定向,因为用cron启动的进程中的任何输出都将邮寄给给定crontab的所有者,因此更好地分别抑制输出和日志错误或通知。

Anyway, crontab allows for a one-minute interval between launches, so you shouldn't really have problems with your scripts timing out. 无论如何, crontab允许两次启动之间的间隔为一分钟,因此您的脚本超时不会真的有问题。 Just make sure your script doesn't send more than 12-13 mails per launch (put a 5-second sleep between mail() calls) and you should do fine. 只要确保您的脚本每次启动不会发送超过12-13封mail()mail()调用之间放置5秒钟的睡眠时间),就应该做得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM