PHP Cron作业窗口和linux。

时间:2023-01-19 01:11:41

I need to set up cron/automatic taks on windows(shared)/linux(shared)/wamp servers.

我需要在windows(共享)/linux(共享)/wamp服务器上设置cron/automatic taks。

the problem is that the project is running on multiple environments.

问题是项目在多个环境中运行。

so what is the best way to set up cron/scheduled taks ?

那么,建立cron/schedule taks的最佳方式是什么呢?

Actually what i need to do is check email servers for new emails and if something found save it to the local DB. If you have any alternative other than cron job then please let me know.

实际上,我需要做的是检查电子邮件服务器的新邮件,如果发现了什么,把它保存到本地数据库。如果你除了克伦工作还有其他选择,请告诉我。

Thanks.

谢谢。

EDIT:

编辑:

As i mentioned in the question i have multiple emails/filtering , so i need to run something on background to fetch data periodically. CRON in linux and Scheduled Tasks on Windows. But the real problem is that i am doing it on a shared hosting ( or it depends the client ) so i cannot use CRON/Scheduled Tasks.

正如我在问题中提到的,我有多个电子邮件/过滤,所以我需要在后台运行一些东西来定期获取数据。linux中的CRON和Windows上的调度任务。但是真正的问题是,我在一个共享的主机上(或者它依赖于客户端)做它,所以我不能使用CRON/预定的任务。

Ex : Project is installed on GOdaddy windows shared hosting , it is a windows server so no support for CRON(normally) and they wont allow to use Scheduled Tasks.

项目安装在GOdaddy windows共享主机上,它是windows服务器,所以不支持CRON(通常),也不允许使用计划任务。

the question is : is there any alternative for CRON/Scheduled Tasks ?

问题是:CRON/计划任务有其他选择吗?

2 个解决方案

#1


2  

Short Answer

I don't know alternatives to CRON/ScheduledTask which would fulfill your need.
I suggest you outsource the schedule to another server, see my possibilities below.

除了CRON/ScheduledTask之外,我不知道还有什么能满足你的需要。我建议你把时间表外包给另一个服务器,看看下面的可能性。

I came up with the following possibilities:

我想到了以下可能性:

Shared hosting with CRON jobs (easiest)

Look for a shared hosting provider who lets you add cron jobs (e.g. through webspace management). HostEurope (german) would be such a host.

寻找一个共享主机提供商,让您添加cron作业(例如通过webspace管理)。HostEurope(德语)将是这样一个主持人。

You own a dedicated (virtual) server

Given you deploy this project to multiple shared servers but own a dedicated (virtual) server for yourself:
Make your script publicly available but guard it with a strong authorization mechansims. (hard-to-guess request token, white-list certain IPs as callees, ...). Set up a cron job on your own server which calls the script on the client's webhost.

假设您将这个项目部署到多个共享服务器上,但您自己拥有一个专用(虚拟)服务器:使您的脚本公开可用,但使用强大的授权机制来保护它。(难以猜到的请求令牌,将某些ip作为callees,…)在您自己的服务器上设置一个cron作业,该作业在客户机的webhost上调用脚本。

You don't own a server

As the last possibility but you don't own a dedicated server.
Setup a virtual machine at some cloud provider (e.g. OpenShift) and add the cronjob there. Don't use this instance for other jobs and it should fullfill your needs perfectly (Reference: https://openshift.redhat.com/community/blogs/getting-started-with-cron-jobs-on-openshift)

最后一种可能,但是您没有专用服务器。在一些云提供程序(例如OpenShift)中设置一个虚拟机,并在那里添加cronjob。不要将此实例用于其他作业,它应该完全满足您的需求(引用:https://openshift.redhat.com/community/blogs/getting-started- started- jobs-on-openshift)

Requirements don't meet infrastructure (likely!)

Your client/project has requirements which don't fit a shared hosting environment. You are strongly encouraged to get a hosting plan fulfilling your true needs. Price differences between shared hosting and first virtual servers or dedicated hosting aren't so steep that investigating is out of question.

您的客户端/项目有不适合共享主机环境的需求。强烈鼓励您获得一个满足您真正需求的托管计划。共享主机和第一个虚拟服务器或专用主机之间的价格差异并不大,因此调查不成问题。

#2


1  

As everyone else suggested if this is a web page you can use wget to run it. If it is a CLI script you will have to run it with php /directory/filepath.php If the actual question is HOW you are going to periodically run it you will have to use cron on *NIX and scheduled tasks on windows server. If you want to automatically install the cron you will have to check the OS and act depending on whether the OS is windows or *NIX. A google search will give you results on how to do it in both environments.

正如其他人所建议的,如果这是一个web页面,您可以使用wget来运行它。如果是CLI脚本,则必须使用php /directory/filepath运行它。php如果实际问题是如何定期运行它,那么必须在*NIX上使用cron并在windows服务器上调度任务。如果您想自动安装cron,您必须检查操作系统并根据操作系统是windows还是*NIX进行操作。谷歌搜索将给出如何在两种环境中进行搜索的结果。

Edit after reds clarification As Samuel Herzog pretty nicely says, on shared hosting you (usually) have a control panel. Most well known for linux are:

如塞缪尔·赫尔佐格漂亮地说,在共享主机上,你(通常)有一个控制面板。最著名的linux是:

Cpanel: http://www.siteground.com/tutorials/cpanel/cron_jobs.htm

Cpanel:http://www.siteground.com/tutorials/cpanel/cron_jobs.htm

Plesk: http://www.hosting.com/support/plesk/crontab

Plesk:http://www.hosting.com/support/plesk/crontab

Webmin: Setting up a cron job with Webmin

Webmin:与Webmin建立cron作业

And for windows I only have some familiatiry with plesk for which the procedure is the same as before.

对于windows,我只对plesk有一些熟悉,它的过程和以前一样。

If you dont have control panel but have shell access (linux) you could follow this tutorial.

如果你没有控制面板但是有shell access (linux),你可以参考本教程。

If you dont have control panel but have remote desktop (windows) you could follow this tutorial.

如果你没有控制面板,但是有远程桌面(windows),你可以参考本教程。

If you dont have any of the above you should follow Samuel Herzog suggestion about a vm on a cloud provider or consider upgrading to a VPS or a dedicated server.

如果你没有以上的任何一个,你应该遵循Samuel Herzog关于云提供商的虚拟机的建议,或者考虑升级到VPS或者专用服务器。

#1


2  

Short Answer

I don't know alternatives to CRON/ScheduledTask which would fulfill your need.
I suggest you outsource the schedule to another server, see my possibilities below.

除了CRON/ScheduledTask之外,我不知道还有什么能满足你的需要。我建议你把时间表外包给另一个服务器,看看下面的可能性。

I came up with the following possibilities:

我想到了以下可能性:

Shared hosting with CRON jobs (easiest)

Look for a shared hosting provider who lets you add cron jobs (e.g. through webspace management). HostEurope (german) would be such a host.

寻找一个共享主机提供商,让您添加cron作业(例如通过webspace管理)。HostEurope(德语)将是这样一个主持人。

You own a dedicated (virtual) server

Given you deploy this project to multiple shared servers but own a dedicated (virtual) server for yourself:
Make your script publicly available but guard it with a strong authorization mechansims. (hard-to-guess request token, white-list certain IPs as callees, ...). Set up a cron job on your own server which calls the script on the client's webhost.

假设您将这个项目部署到多个共享服务器上,但您自己拥有一个专用(虚拟)服务器:使您的脚本公开可用,但使用强大的授权机制来保护它。(难以猜到的请求令牌,将某些ip作为callees,…)在您自己的服务器上设置一个cron作业,该作业在客户机的webhost上调用脚本。

You don't own a server

As the last possibility but you don't own a dedicated server.
Setup a virtual machine at some cloud provider (e.g. OpenShift) and add the cronjob there. Don't use this instance for other jobs and it should fullfill your needs perfectly (Reference: https://openshift.redhat.com/community/blogs/getting-started-with-cron-jobs-on-openshift)

最后一种可能,但是您没有专用服务器。在一些云提供程序(例如OpenShift)中设置一个虚拟机,并在那里添加cronjob。不要将此实例用于其他作业,它应该完全满足您的需求(引用:https://openshift.redhat.com/community/blogs/getting-started- started- jobs-on-openshift)

Requirements don't meet infrastructure (likely!)

Your client/project has requirements which don't fit a shared hosting environment. You are strongly encouraged to get a hosting plan fulfilling your true needs. Price differences between shared hosting and first virtual servers or dedicated hosting aren't so steep that investigating is out of question.

您的客户端/项目有不适合共享主机环境的需求。强烈鼓励您获得一个满足您真正需求的托管计划。共享主机和第一个虚拟服务器或专用主机之间的价格差异并不大,因此调查不成问题。

#2


1  

As everyone else suggested if this is a web page you can use wget to run it. If it is a CLI script you will have to run it with php /directory/filepath.php If the actual question is HOW you are going to periodically run it you will have to use cron on *NIX and scheduled tasks on windows server. If you want to automatically install the cron you will have to check the OS and act depending on whether the OS is windows or *NIX. A google search will give you results on how to do it in both environments.

正如其他人所建议的,如果这是一个web页面,您可以使用wget来运行它。如果是CLI脚本,则必须使用php /directory/filepath运行它。php如果实际问题是如何定期运行它,那么必须在*NIX上使用cron并在windows服务器上调度任务。如果您想自动安装cron,您必须检查操作系统并根据操作系统是windows还是*NIX进行操作。谷歌搜索将给出如何在两种环境中进行搜索的结果。

Edit after reds clarification As Samuel Herzog pretty nicely says, on shared hosting you (usually) have a control panel. Most well known for linux are:

如塞缪尔·赫尔佐格漂亮地说,在共享主机上,你(通常)有一个控制面板。最著名的linux是:

Cpanel: http://www.siteground.com/tutorials/cpanel/cron_jobs.htm

Cpanel:http://www.siteground.com/tutorials/cpanel/cron_jobs.htm

Plesk: http://www.hosting.com/support/plesk/crontab

Plesk:http://www.hosting.com/support/plesk/crontab

Webmin: Setting up a cron job with Webmin

Webmin:与Webmin建立cron作业

And for windows I only have some familiatiry with plesk for which the procedure is the same as before.

对于windows,我只对plesk有一些熟悉,它的过程和以前一样。

If you dont have control panel but have shell access (linux) you could follow this tutorial.

如果你没有控制面板但是有shell access (linux),你可以参考本教程。

If you dont have control panel but have remote desktop (windows) you could follow this tutorial.

如果你没有控制面板,但是有远程桌面(windows),你可以参考本教程。

If you dont have any of the above you should follow Samuel Herzog suggestion about a vm on a cloud provider or consider upgrading to a VPS or a dedicated server.

如果你没有以上的任何一个,你应该遵循Samuel Herzog关于云提供商的虚拟机的建议,或者考虑升级到VPS或者专用服务器。