BFD Calendar Posted January 24, 2014 Posted January 24, 2014 I have a template that includes a php mail script sending the results of an array. It works fine when I load the page in a browser, it sends the page content like it should. I want this to happen every day at 1.00 am, so I have a Cron Job (Tasks Scheduler on my server) scheduled to perform the script. Command executed : /usr/local/bin/php.ORIG.5_3 -c /usr/local/lib/php.ini-2 /homez.183/birthfac/www/site/templates/bfd_mailer.php But I get a PHP Fatal error: Call to a member function find() on a non-object on line 51: $features = $pages->find("parent=/events/, bfd_day.name=$todayday, bfd_month.name=$todaymonth, sort=bfd_year"); So I presume the doesn't understand the ProcessWire code "parent=/events/".... Any suggestions for a workaround or solution?
adrian Posted January 24, 2014 Posted January 24, 2014 It doesn't know"$pages". Is the mail script bootstrapped on PW or are you calling a template page directly from the cron job? You might try using wire('pages'), I am not sure this will work, depending on how that script is set up. I think the most reliable and easiest way would be to use the LazyCron PW module: http://modules.processwire.com/modules/lazy-cron/
horst Posted January 24, 2014 Posted January 24, 2014 Maybe you can configure your cronjob to fetch the url via wget like: wget --quiet --no-cache -O - http://www.your-site.com/page-url-with-mail-script/ > /dev/null This way you don't need to change any code, only your cronjob. (https://www.google.de/search?q=site:processwire.com/talk+ryan+wget+cron+null)
BFD Calendar Posted January 24, 2014 Author Posted January 24, 2014 Horst, the 'tasks scheduler' only allows me to enter the url of a script/page on the server and fix a time when it should be executed. I can't edit the cronjob itself (or I haven't figured out where to do it). Adrian, 'bfd_mailer.php' is the template that has the mail script. Load it in a browser and the content is sent. 'wire('pages')' didn't do the trick. LazyCron looks promising, but I see Captain Hook luring around the corner again. Still gobbledegook to me but I guess I'll have put my teeth in there sooner or later. I kinda get the idea behind it but applying it is something else.... Basically the hook says 'myFunc' is sending the email (script in template) 'everyDay'? Or is 'myFunc' finding the pages AND sending the email? And it should be not just 'everyDay' but every day at 1.00 am. So should I distill it all from http://processwire.com/api/hooks/ and http://processwire.com/api/hooks/captain-hook/ or are there more practical examples out there? Anyway, thanks until now.
horst Posted January 24, 2014 Posted January 24, 2014 Horst, the 'tasks scheduler' only allows me to enter the url of a script/page on the server and fix a time when it should be executed. I can't edit the cronjob itself (or I haven't figured out where to do it). Ah, ok. You may also try to create a simple php script somewhere outside of pw with this content: <?php header("location: http://www.your-site.com/page-url-with-mail-script/"); or with this one: <?php file_get_contents("http://www.your-site.com/page-url-with-mail-script/"); and call that with your cronjob. 2
Ableson Posted January 25, 2014 Posted January 25, 2014 Use easycron.com. Works similarly than triggering in browser.
teppo Posted January 25, 2014 Posted January 25, 2014 But I get a PHP Fatal error: Call to a member function find() on a non-object on line 51: $features = $pages->find("parent=/events/, bfd_day.name=$todayday, bfd_month.name=$todaymonth, sort=bfd_year"); So I presume the doesn't understand the ProcessWire code "parent=/events/".... That error is caused by the fact that you run this file without involving ProcessWire at all. You can't just run template file "standalone" and expect it to automatically load ProcessWire, you know Solution @horst provided above is most likely what you need here (or external / real cron job instead of this awfully limited scheduler thing you're using now). Then again, if this is the only reason you need that template, i.e. it doesn't need to be web-accessible, you could forget whole template and page thing and simply place a PHP file somewhere your scheduler can access (such as your PW root directory) and in that file bootstrap PW and write any program logic you need. Point your scheduler to that file and you're all set. 2
Martijn Geerts Posted January 25, 2014 Posted January 25, 2014 What I mostly do with cronjobs is to create a page inside /processwire/ and give guest acces to that page template. That template is only used for that 'cron' page. So after the page is created, disallow other pages using that template. Say your page with guest access set and is named cron, your cron job can visit yourdomain.ext/processwire/cron/.
BFD Calendar Posted January 25, 2014 Author Posted January 25, 2014 Thanks all. Horst's solution did the trick. I tried <?php header("location: http://www.your-site.com/page-url-with-mail-script/"); before but it didn't work. <?php file_get_contents("http://www.your-site.com/page-url-with-mail-script/"); however worked. Teppo, the page I'm calling is indeed hidden because I'm using it only to send my daily array to Blogger. As soon as it runs smooth Blogger is configured to accept and post automatically. And of course the page shouldn't be reachable otherwise.
teppo Posted January 25, 2014 Posted January 25, 2014 Teppo, the page I'm calling is indeed hidden because I'm using it only to send my daily array to Blogger. As soon as it runs smooth Blogger is configured to accept and post automatically. And of course the page shouldn't be reachable otherwise. Glad to hear that you found a solution, but in a case like this I'd really suggest taking a look at bootstrap method. It's perfect for tasks like these, where you don't really want or need actual page, just code that can access data and/or features of ProcessWire. 1
BFD Calendar Posted January 25, 2014 Author Posted January 25, 2014 Always eager to learn something new! Unless it's beyond my comprehension.... 2
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