Cron

From PhpCOIN Documentation

Jump to: navigation, search

Contents

Automation Capabilities

Cron is a *nix timer/scheduling daemon that runs in the background on most web-servers. Scripts or other programs can be registered with the Cron daemon to run "every so often". The equivalent for Windows is "Scheduled Tasks".

phpCOIN has several functions that must be called at regular intervals to handle automatic processing of invoices, late payment "nag" emails, and automatically creating new recurring invoices. The invoice functions are all contained within /coin_cron/invoices.php, which must be run once each day, every day ~ no exceptions, or you may end up not having some invoices created or nag emails sent.

There is also an optional function (helpdesk.php) that will connect to an email box, check to see if messages are from existing clients, and if so either add a reply to a helpdesk ticket or create a new helpdesk ticket. This is useful if you have clients who hit "reply" to a helpdesk ticket rather than logging in to phpCOIN to respond, or who do not use the helpdesk and instead insist on emailing help requests. The helpdesk-import functions are contained within /coin_cron/helpdesk.php, which can be run as often as you want phpCOIN to check your email, or not run at all ~ your choice.

There is another optional function (paypal.php) that will connect to an email box, check to see if messages are from PayPal, and if so try to create a payment and apply it to an invoice. This is an alternative to the PayPal IPN system.


Configuring phpCOIN Cron Jobs

The /coin_cron files built-in to phpCOIN can be called two different ways:

1: The first is via curl or wget to simulate being called by a web-browser. If you call the file(s) this way, there are no configuration settings within phpCOIN for you to change. The actual command to execute would be curl/wget, with the URL to the cronfile as a parameter, ie:

 curl http://my.phpcoin.com/phpCOIN/coin_cron/helpdesk.php

2: The other method is to process the file(s) straight from the command line by php. In this event, you must tell phpCOIN where it is located, because the automatic 'where am I' code depends on being called from a web-browser. Edit the following line of the /coin_cron/cron_config.php file:

$_COINURL = 'http://my.phpcoin.com';

Change the http://my.phpcoin.com part of the line to the actual URL of your phpCOIN installation. You must keep the single quotes in place. If you placed the phpCOIN files in a directory called billing, you would have $_COINURL = 'http://my.phpcoin.com/billing'; If your phpCOIN installation runs under SSL, you would have $_COINURL = 'https://my.phpcoin.com'; Several examples are included in the comments of the file. The actual command to execute would be the path to the cronfile, ie:

 /home/html/path_to_phpcoin/coin_cron/helpdesk.php


Scheduling the phpCOIN Cron Jobs

Depending on your server setup you may need to edit crontab files manually, or you may have access to a control panel with scheduling capabilities.

Direct crontab editing

Add the following lines to your crontab

0,10,20,30,40,50 * * * * curl -s http://my.phpcoin.com/phpCOIN/coin_cron/helpdesk.php
30 4 * * * curl -s http://my.phpcoin.com/phpCOIN/coin_cron/invoices.php

This will run the helpdesk-import script every 10 minutes, and the invoices script once a day at 4:30 am. Feel free to use your own time intervals if you want them to run at different times ~ this is just an example. curl is just a plain text web browser. If curl doesn't work you can try lynx (though the -s may not be appropriate for lynx) or wget.

Control Panel Settings

For those of you using a reseller account on a web-host provider, you may have a cPanel or Plesk entry named "Cron Jobs" or something similar. Clicking it usually gives two options ~ Standard, and Advanced (Unix Style)

Choose "Standard" and you will see a screen (might be called "Entry 1", or a higher number if you already have a cron job set-up) that has "command to run" and then a number of boxes with time and date (day & month) options. You might also have an option to send the results of the crontab to an e-mail address. If so, please do enter your e-mail address.

Enter the appropriate phpCOIN filename in the command to run box, making sure that the path to the file is correct. We recommend that you run the invoice.php daily and any other desired files hourly. To do this choose the best minutes (0 is on the hour - you will have the choice of 0 to 59) and in the hours box select every hour. Check the other boxes but they are most likely already set to every day, weekday, and month. Click the [save crontab] button. Follow the same procedure for invoices.php. Select a time in minutes (not one of the every options) and likewise in hours. To choose 3:15 am, select "15" in minutes and "3" (3am) in hours. Make sure "every day" is selected in days, and the "every" option is selected in the remaining two. Again, save this new entry by clicking the [save crontab] button.


Output from cronjob

When run, the /coin_cron/helpdesk.php file can provide the aggregate results of all messages processed, or it can provide step-by-step details of each message processed. Aggregate results is recommended for normal operation, while detailed results is recommended for trouble-shooting.

In phpCOIN v1.2.6 and higher, goto Admin -> Parameters -> automation -> helpdesk -> Helpdesk: Auto-import verbose. Set it to YES for detailed results or NO for aggregate results.

In phpCOIN v1.2.5 or lower, edit the value of the variable $Silent in /coin_cron/helpdesk.php

$Silent=0;

Will give detailed results, while

$Silent=1;

will give aggregate results

RackSpace Hosting

Personal tools