Red
Red

Reputation: 6378

PHP Cron job windows and linux

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 ?

Upvotes: 2

Views: 2458

Answers (2)

Samuel Herzog
Samuel Herzog

Reputation: 3611

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.

Upvotes: 2

tix3
tix3

Reputation: 1152

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.

Upvotes: 1

Related Questions