Jump to content

Alternative to cron?


Hijack

Recommended Posts

Hey everyone,

 

So I'm a complete PHP noob and have very basic knowledge of PHP - everything I learn is from tutorials online. I created a website which monitors Stock Exchange data for a particular stock exchange by downloading a CSV file from the Stock Exchange's website containing all the stock data - as this is the only way this particular exchange provides its data to 3rd parties. Now, my PHP system takes this CSV file, reads it and inserts the data into a MySQL database. Then, the function of my site is that users can create alerts for particular stocks that they are watching, and my website will send them an email when the stock price of the stock that they are watching goes above or below a particular value that they specify. Simple!

 

However, since my MySQL database always needs the most recent version of the stock prices, the way I did this in the past was by using Cron every minute to download the file off the exchange's website, and insert the data into my database. I realise that this is quite inefficient, but my main problem is actually that the only way I can do cron every minute is by paying for my own Virtual Dedicated Server as normal shared hosting won't let me run a script that frequently.

 

What I am here to ask is if any of you know an alternative way that I can constantly update the price data in my database i.e. an alternative to cron. I hear that you can run PHP scripts as 'daemons' but I'm not sure how this works nor whether I can do this with normal shared hosting. I cannot afford a Virtual Dedicated server any longer and so need a solution which is compatible with normal, cheap shared hosting. Any help would be much appreciated!

 

 

Link to comment
Share on other sites

I used pseudo-cron a number of time on webhosts that don't provide cron abilities.

 

It is fairly easy to setup and use and is driven by hits to your site.

 

So if you have a general settings file or menu or whatnot that all your pages use when you get hits, you place a snippet in that code and hits to your site drive the cron scheduling.

 

If there are no hits, it will play catchup for tasks that should have happened.

 

Usually regular tasks like backup up the site's database are run using cron jobs. With cron jobs, you can exactly plan when a certain command is to be executed. But most homepage owners can't create cron jobs on their web server – providers demand some extra money for that.

 

The only thing that's certain to happen quite regularly on a web page are page requests. This is where pseudo-cron comes into play: With every page request it checks if any cron jobs should have been run since the previous request. If there are, they are run and logged.

 

http://ly.tnet.com/y

 

It works good for a lot of general scheduling... but if you have to have something updated on a real regular schedule, you could setup a page that you call from your workstation via it's scheduler instead.  Their are some examples out on the net.

Link to comment
Share on other sites

I have the same issue for some weather related sites where I use a hit a minute to collect data that has been saved on the site but needs to be added to a running log.  For me it was an easy solution as I have cron.  For others however, it wasn't because the use a cheap inexpensive ($10 year) web host which don't allow cron at all.  Other sites only have 1/2 hour or hour increments.

 

The solutions I came up with were.

 

1) I can schedule a job on my site which has cron to call their site (a page called cron.php).  It uses a code in the call so that other hits to that page don't do anything.

2) Setup a schedule on a winbox which does basically the same thing.  You can do this with some simple vb scripts and the scheduler of your workstation, but you have to keep it running.

3) Run a utility on your win box which does the same thing. Never found a free one I liked, did see some paid ones.  all of them would need to keep running.  Running as a service would be better.

 

Link to comment
Share on other sites

Thanks for all your help. Yeah I see how that could work but the problem is I live in one country and am a university student in another so for half the year I only have a laptop. Basically can't manage the logistics of having a computer running permanently.

Link to comment
Share on other sites

Find a friend with a Unix/Linux server with cron that can do it for you.

 

File: cron.php

 

<?php
if(isset($_GET['c']) && $_GET['c'] == "292081") {
	// Insert page you want to call or do the function here
}
?>

 

http://www.somepage.somewhere/cron.php?c=292081

 

The code or in this case c is just to keep from some random hit from triggering it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.