Biorn Posted January 23, 2013 Share Posted January 23, 2013 Hi guys.. Long time no see... Well, Im back to some web programming again, I have been on tour with a Odense symphony orchestra.. Ok, I havent played with cron or lazycron before, so I was wondering, can it be used to auto refresh a website? I startet a digital signage project, where Im planning to use processwire as the core, and then I need it to refresh or update the player browser every day at midnight, and maybe doing the day, when some of the items are done.. Hope you can give me an answer... // Biorn Link to comment Share on other sites More sharing options...
diogo Posted January 24, 2013 Share Posted January 24, 2013 Not an expert on this, but if what you want is to refresh the page in the browser (is it?) the indicated would be javascript. Maybe something like this would work (very rough and written in the browser... just to illustrate a point) // checks every hour if the hour of the day is 0, and if so, reloads the page setTimeout(function(){ var d = new Date(); if( d.getHours() == 0 ){ window.location.reload(); }; }, 3600000); Link to comment Share on other sites More sharing options...
Wanze Posted January 24, 2013 Share Posted January 24, 2013 Hi Bjorn, not exactly sure if get what you want to do From the docs: It is called 'lazy' because it's triggered by a pageview, so the interval is guaranteed to be at least the time requested (and maybe more) rather than exactly the time requested. The more pageviews your site gets, the closer it is. This is fine for most cases, but if you need it to be fully accurate I'll describe how you can make it not-lazy a little further down. http://modules.processwire.com/modules/lazy-cron/ So if you need your refresh exactly at midnight, a Cronjob would be the better solution. See the last paragraph, "How to make it not lazy" in the link above. Cheers Link to comment Share on other sites More sharing options...
Biorn Posted January 31, 2013 Author Share Posted January 31, 2013 HI guys.. I want to update the "player" every 5 mins for what event that are finish, and at midtnight for the next days events. and maybe a "focus" thing that can be shown every XX mins.. I have looked a bit into lazy-cron, but Im not getting it.. maybe im just blinded by myself?? Link to comment Share on other sites More sharing options...
ryan Posted February 1, 2013 Share Posted February 1, 2013 Biorn, here's some more info about LazyCron: http://processwire.com/api/modules/lazy-cron/ Ultimately, it's lazy, which you will notice if you don't have consistent traffic to your site. So if you need something to run every 5 mins consistently, then you should either use regular cron (from your server) or use regular cron to ping a non-cached page on your website (thus triggering Lazycron). Link to comment Share on other sites More sharing options...
Biorn Posted February 1, 2013 Author Share Posted February 1, 2013 I have looked into it, and I cant get it to work.. Maybe Im going blind, og just loosing my mind and brains.. In this case there is not a lot of trafic, Its a info screen with, times, locations and classes. But its the proof-of-concept, that a digital signage system can be made, and run from processwire.. And in the future, the "player" client must be known by the master server.. have a peek: http://sign.chrisb.dk/ this is powered by: google calender loader, Color picker, Repeater, LazyCron (in the future) and Page Render IP restriction. And the player is a Raspberry Pi, running Raspbian and booting Chromium into kios mode, and it runs very smooth.. Except the Cron stuff.. But, maybe I chould have a look into the regular cron ping solution.. Hmm.. Ill be back... PS.. Im allways getting a smile on my face, and a lot happyer, when I see your big smile in your profile pic Ryan.. And thanks for that.. // Cheers... 1 Link to comment Share on other sites More sharing options...
teppo Posted February 2, 2013 Share Posted February 2, 2013 Ok, I havent played with cron or lazycron before, so I was wondering, can it be used to auto refresh a website?I startet a digital signage project, where Im planning to use processwire as the core, and then I need it to refresh or update the player browser every day at midnight, and maybe doing the day, when some of the items are done.. Just to make sure: are you actually trying to run code under the hood or perhaps just refresh the browser window at specified interval? If your intention is just to reload / refresh the browser window, you'd probably want to use JavaScript or meta refresh tag for that. Cron (whether lazy or regular) is intended to run code under the hood at regular interval, but it won't directly affect browsers / clients viewing the content. If your application needs to fetch content from somewhere (such as Google Calendar), you could use a combination of lazy cron and JavaScript to achieve this, though lazy cron part would be somewhat irrelevant as long as this is just a proof of concept. For the time being you could also have your page check for new content on each page load. If you're interested in taking this concept a step further, you could also take a look at something like https://github.com/viljamis/Remote-Preview/ as a reference project. It has certain similar features to what you're building here (unless I'm completely mistaken) - primarily that it updates client machines browser window on an interval. The thing that makes Remote Preview feel more sophisticated is that refresh is only toggled if an AJAX query to a text file containing an URL confirms that it has changed since previous reload. Difference between that approach and a plain meta tag / JavaScript refresh isn't huge, but it definitely makes it seem more elegant 1 Link to comment Share on other sites More sharing options...
ryan Posted February 2, 2013 Share Posted February 2, 2013 You might find the attached LazyCronTest.module helpful. This basically just demonstrates LazyCron in action. Install this module after LazyCron is installed, and it'll record a log entry every 5 minutes (or so) to /site/assets/logs/lazytest.txt. That's assuming the site is getting non-cached pageviews so that LazyCron gets a chance to run. LazyCronTest.module <?php class LazyCronTest extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Lazy Cron Test', 'version' => 100, 'summary' => 'Tests lazy cron by writing to a log file in /site/assets/logs/lazytest.txt', 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookAfter('LazyCron::every5Minutes', $this, 'lazyTest'); } public function lazyTest($event) { $seconds = $event->arguments[0]; $log = new FileLog($this->config->paths->logs . 'lazytest.txt'); $log->save('LazyCron 5 minute test - ' . date('Y-m-d H:i:s') . " - $seconds seconds"); } } Here's an example of the log file it generates: 2013-02-02 11:19:02:LazyCron 5 minute test - 2013-02-02 11:19:02 - 356 seconds 2013-02-02 11:24:04:LazyCron 5 minute test - 2013-02-02 11:24:04 - 302 seconds 2013-02-02 11:31:52:LazyCron 5 minute test - 2013-02-02 11:31:52 - 468 seconds 2013-02-02 11:37:22:LazyCron 5 minute test - 2013-02-02 11:37:22 - 330 seconds 2013-02-02 11:43:14:LazyCron 5 minute test - 2013-02-02 11:43:14 - 352 seconds 2013-02-02 11:49:13:LazyCron 5 minute test - 2013-02-02 11:49:13 - 359 seconds 2013-02-02 11:54:37:LazyCron 5 minute test - 2013-02-02 11:54:37 - 324 seconds 2013-02-02 12:00:07:LazyCron 5 minute test - 2013-02-02 12:00:07 - 330 seconds 2013-02-02 12:05:07:LazyCron 5 minute test - 2013-02-02 12:05:07 - 300 seconds 2013-02-02 12:12:42:LazyCron 5 minute test - 2013-02-02 12:12:42 - 455 seconds 2013-02-02 12:18:35:LazyCron 5 minute test - 2013-02-02 12:18:35 - 353 seconds 2013-02-02 12:23:37:LazyCron 5 minute test - 2013-02-02 12:23:37 - 302 seconds 2013-02-02 12:30:54:LazyCron 5 minute test - 2013-02-02 12:30:54 - 437 seconds 2013-02-02 12:36:22:LazyCron 5 minute test - 2013-02-02 12:36:22 - 328 seconds 2013-02-02 12:41:57:LazyCron 5 minute test - 2013-02-02 12:41:57 - 335 seconds 2013-02-02 12:50:48:LazyCron 5 minute test - 2013-02-02 12:50:48 - 531 seconds 2013-02-02 12:56:58:LazyCron 5 minute test - 2013-02-02 12:56:58 - 370 seconds 2013-02-02 13:03:03:LazyCron 5 minute test - 2013-02-02 13:03:03 - 365 seconds 2013-02-02 13:15:03:LazyCron 5 minute test - 2013-02-02 13:15:03 - 720 seconds 2013-02-02 13:26:03:LazyCron 5 minute test - 2013-02-02 13:26:03 - 660 seconds 2013-02-02 13:31:46:LazyCron 5 minute test - 2013-02-02 13:31:46 - 343 seconds 2013-02-02 13:37:37:LazyCron 5 minute test - 2013-02-02 13:37:37 - 351 seconds Notice how the number of elapsed seconds is always more than 5 minutes (and sometimes a lot more). That's just because it has to be triggered by a PageView. In most cases, this is okay because a lack of pageviews usually means there's nobody there to see what was updated anyway. 2 Link to comment Share on other sites More sharing options...
diogo Posted February 5, 2013 Share Posted February 5, 2013 As I told, I'm not an expert, but for this I will stick to my answer 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now