Hijack Posted December 4, 2011 Share Posted December 4, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/ Share on other sites More sharing options...
dweeber Posted December 4, 2011 Share Posted December 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294430 Share on other sites More sharing options...
Hijack Posted December 4, 2011 Author Share Posted December 4, 2011 I see what youre getting at there, but the problem is I cant rely on there being a page request every minute Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294431 Share on other sites More sharing options...
scootstah Posted December 4, 2011 Share Posted December 4, 2011 I see what youre getting at there, but the problem is I cant rely on there being a page request every minute Then no, there is no alternative. Of course, you could always set up a cron on your own machine to hit the website every minute. Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294432 Share on other sites More sharing options...
dweeber Posted December 4, 2011 Share Posted December 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294439 Share on other sites More sharing options...
Adam Posted December 4, 2011 Share Posted December 4, 2011 As I think dweeber is getting at, if shared hosting is essential you could use your own computer to download the stock data, then push to your remote server via a simple API. Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294440 Share on other sites More sharing options...
Hijack Posted December 4, 2011 Author Share Posted December 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294441 Share on other sites More sharing options...
dweeber Posted December 4, 2011 Share Posted December 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294443 Share on other sites More sharing options...
Adam Posted December 4, 2011 Share Posted December 4, 2011 Do you have command line access to the server? You could execute a script and leave it running, with a sleep in-between updates. Not perfect but might be the best option... Quote Link to comment https://forums.phpfreaks.com/topic/252472-alternative-to-cron/#findComment-1294450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.