2

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

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

so what is the best way to set up cron/scheduled 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.

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.

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

Red
  • 6,230
  • 12
  • 65
  • 112
  • You could write your scripts in PERL, python, php etc then it can run on any platform which has the language installed – Iesus Sonesson Feb 25 '13 at 08:56
  • @lesus What are you saying ? everything is written in PHP. the question is how can we setup automated tasks ? – Red Feb 25 '13 at 09:01
  • are the tasks ment to run web scripts or CLI scripts? If it's web scripts you can install wget in both servers and do a simple wget towards the file you are about to run. http://gnuwin32.sourceforge.net/packages/wget.htm On linux it looks something like this wget http://URL/FILE.php -qO /dev/null on windows it would be something like C:\PATH\TO\wget http://URL/FILE.php -qO C:\TEMP If it is command line you use C:\PATH\TO\php.exe SCRIPT.php and /PATH/TO/php script.php – Iesus Sonesson Feb 25 '13 at 09:06
  • 1
    you can pipe email to a script, and use that to check the email contents, no cron required –  Feb 25 '13 at 09:08
  • if its in PHP, i would just use cURL that points to the php page. that should work in either windows or linux – kennypu Feb 25 '13 at 09:15
  • @lesus so how can i configure that `wget` ? i need to run this about 10 -50 per hour. – Red Feb 25 '13 at 12:27
  • @Dagon it will work if the email folders are small. My case is different i have multiple mail servers with many `filter` conditions. Thats why i am saying about background service. – Red Feb 25 '13 at 12:28
  • @Red You don't configure wget, you configure the scheduler, in both cron and windows task scheduler you set up which minute by which hour you want to run the task. wget, just access the file over itnernet for the script to run – Iesus Sonesson Feb 25 '13 at 15:27
  • @red just read the question again, and i have been way off sorry if thought the question was how to run a script by from or win task scheduler – Iesus Sonesson Feb 25 '13 at 16:09

2 Answers2

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.

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.

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.

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)

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.

Samuel Herzog
  • 3,561
  • 1
  • 22
  • 21
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.

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:

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

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

Webmin: Setting up a cron job with Webmin

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

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

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

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.

Community
  • 1
  • 1
tix3
  • 1,142
  • 8
  • 17
  • the question is not `how to run that script` and it is `how to setup something that which periodically run that script`. – Red Feb 25 '13 at 12:30
  • 1
    Updated the answer with some suggestion (control panel specific) but +1 to Samuel Herzog answer :) – tix3 Feb 25 '13 at 14:57