Cron Job

I am developing a web application with PHPMaker in which I need to implement CRON Job PHP file. This PHP script will need to interact with the Database and take some actions after processing the information gathered from database. Here, I want to use PHPMaker’s DbHelper class for interacting with database. But the PHP file which will be executed by CRON will be a stand-alone and hence it won’t load PHPMaker framework.

I assume I will need to INCLUDE some of the core PHPMaker files related to database connectivity before I can avail the luxury of easy to use DbHelper functions; but I’m still not able to get the things right. Can someone please tell me which files I need to include in my stand-alone PHP file which is to be executed by CRON? Also, what should be the sequence of call to functions? I will need to Connect to the DB before I call ExecuteRow etc functions, right? I never encountered this before since the DbHelper() was available to me right there with DB Connection already established.

Please guide me to make use of PHPMaker’s DbHelper in a PHP Script which will be executed by CRON.Thanks!

Since you don’t want to use PHPMaker framework completely, but you still want to include some of the core PHPMaker files related to database connectivity, then I assume you will not enable “Include common files” from the Custom File, so you may try this trick: hkvforums.com/viewtopic.php?f=18&t=43518

Thanks so much for your reply. I tried your code and facing a new issue. It’s related to Security.

I have implemented Security in this application. Now, when CRON attempts to execute the PHP script, it is executed as stand-alone script and hence there is no login session active. As a result, it redirects me to the Login page. Is there any way which will allow me to manually perform login and set the Session so it will continue to execute the PHP script?

ORIs there any other alternative you can think of?

Certainly, I can completely drop the idea of using PHPMaker DbHelper and carry out traditional PHP MySQL coding to deal with the record sets. But it will be of great help if I can somehow gain access to DbHelper.

Ok, I logged in as User and then executed the script, just to see if everything is working fine and it’s only about Security.

Surprisingly, I get following error:Fatal error: Call to undefined function ExecuteScalar() in path/to/jobs.php on line 29I have copied the same code as in your post with sql query related to my table structure of course.

Make sure you have already put the “jobs.php” file in the root of your generated web application.

I’m not totally sure if you don’t want to load the framework for a reason. Also don’t know if my solution is elegant and/or there are better ways, but what I did with my cronjob works:

  1. Used an generated empty PHPMaker page, and put the standalone code in there. Name: cronmailer.php
  2. Gave the cronjob it’s own username/password, i.e. cjmailer
  3. The cronjob accesses login.php via wget (/usr/bin/wget) w un/pw
  4. I redirect in Server Events/Other/Default Page/Page_Redirecting with
    if (IsLoggedIn()) {
    $username=CurrentUserName();
    $userlevel=CurrentUserLevel();
    if ($username==“cjmailer”) {
    $url=“cronmailer.php”;
    }
    }

works without any hassles

@bobmulder5555: wow! You have a very different approach. This is quite unique in its way as it simulates the Login and then redirects to the cron script. I will try this; thanks for sharing your idea.

Oh maybe useful info: each day every doctor in a (Dutch) doctors post will get an email reminder of his/her shift in 3 days. So THAT is what this cronjob has to do: every day at 7 am it kicks to life cronmailer.php which then does a " normal" search in the database for WHICH 7 or 17 (depending in weekday or weekend day) have shifts in 3 days.

And THEN sending that reminder to those doctors, after which it just logs out again until it is kicked to life the next day by that cronjob.

The REMINDER of course is ALSO just a template which a super-user can easily change. And this template fills itself, for each to-be sent e-mail, with WHO, what SHIFT, those shift times (also from the database) etc.

For Covid-19 for example, we saw some recurring questions from doctors. So the Super-user just added these questions and answers to the bare-bone template. AND added a link to a FAQ page.

NOW the doctors get MORE cronjobs/e-mails. Same mechanism. Now my system also supports a fully auto trading system the doctors use to trade or sell a shift with another doctor.
They auto see all their remaining shifts of that year + all shifts of next year (once approved and available). They select the new doctor, see all THOSE shifts and select one. SOME checks and balances remain, so trade is sent for approval to a central organization of their own. Once approved (again one mouse click by a super-user or director) the trade is auto-updated in the actual roster and everybody can see the NEW doctor.

Everybody gets an auto-email IF somebody has offered his/her shift for whenever on THAT day. On Friday EVERYBODY gets ALL current unfulfilled shifts for trade and/or sale, even if THAT Friday nothing has happened. (this is what doctors are used to, although it is NOT logical. A hospital for instance is ONLY interested in unfulfilled trade/sell shifts for the coming two weeks. THAT is the average attention span of a doctor). So I now give then TWO overviews in the same template: what they are used to AND only the coming two weeks. At least every Friday everybody gets THIS overview. Better than nothing.

Hi Bob,
Thanks for your insight, this has really helped. My project is protected with reCAPTCHA, you can’t just get past this. Is there a way to get around this?
Thank you