phpCOIN

  Reply to this topicStart new topicStart Poll

> Cron Jobs, and other considerations
lightman
  Posted: January 27, 2008 03:19 pm
Quote Post


The Janitor
***

Group: Admin
Posts: 3,639
Member No.: 3
Joined: August 25, 2006



So you have a shinny new installation of phpCOIN all set up and running the way you want it smile.gif Now is the time to think about that last step of applying some automation to the system in the form of the invoices and helpdesk cron jobs.

I thought I would share with the community how I have my cron jobs set up on my LAMP server and discuss some considerations you might want to take into account.

The invoice cron job is a simple matter to set up. It has to run only once a day and optionally mail you a report as to what it did.

I run mine at 10:00 server time every morning to give me a chance to get into the office and review and edit if necessary any pending invoices that are scheduled to be made due when the cron job runs.

The command I choose is to call php directly to process the file and the cron job line looks like this:
CODE
0 10 * * * /usr/bin/php /var/www/vhosts/my.phpcoin.com/httpdocs/coin_cron/invoices.php

This runs the invoices.php and emails me with the results.

That was all really easy but when I started to look at how I could use the helpdesk import, things got a lot more complicated sad.gif

The issue is, under the data retention legislation, I need to keep a copy of all the emails sent to me so I have to leave on server all the mails I receive in all the various mail accounts.

So what's the problem you ask - phpCOIN can do that by not switching on the 'delete imported mails' parameter. Quite right - BUT - after a few months, every time the mail import cron runs - it has to keep looking through hundreds (thousands ?) of mails that it has already seen and not imported during any previous cron runs AND its going to re-import over and over again, any mail it can match against the import criteria (remember we cant ask phpCOIN to delete imported mails since we need to keep them in their received format to comply with data retention legislation).

Obviously the situation was unworkable in this format since I didn't want multiple imports of the same mail, nor did I want the processing overheads associated with having to re-read all the stored mail messages every cron run - time to think about this and have a play biggrin.gif

I started by creating a new mailbox on the mail server and copy forwarding all the messages I received to the support box into this new mailbox - this gave me a box I could poll with the helpdesk import without touching the repository of mail in the main support mailbox.

I set up my phpCOIN to connect to this new mailbox using imap AND to delete imported mails from server (to prevent multiple imports of the same mail) and set up the cron job to run every 20 mins. Everything worked beautifully BUT we still had the issue of all the mails the import DIDN'T catch still sitting in the box, growing in size, and being re-read every time the cron job ran.

My first thought to solve this problem was to create yet another cron job to periodically delete all mails out of this new mail folder - after all - they have already been checked and rejected by the import process, I have the original copies still in the support mailbox and it would dramatically cut down processing time and overheads if the helpdesk import was only looking at mails it hadn't seen before each time it ran. (See Note 1)

Not a bad solution and certainly workable, but was there a more elegant way to achieve this ? Of course - if the helpdesk.php file could mark emails for deletion that it had imported and then delete them, why couldn't it mark ALL the emails it had seen for deletion ? It CAN biggrin.gif By adding the imap_delete line further up in the message processing loop, we can mark all messages for deletion as they are looped through and, at the end of the loop, having imported any that meet the import criteria, delete them from the server - now we are getting somewhere biggrin.gif biggrin.gif biggrin.gif (See Note 1)

The cron job for this process looked like this:
CODE
0,20,40 * * * * /usr/bin/php /var/www/vhosts/my.phpcoin.com/httpdocs/coin_cron/helpdesk.php

That left me with the irritation of receiving an email every 20 mins when the cron job ran - not a problem - we can redirect the standard output to /dev/null by adding the code
CODE
> /dev/null
but this will still mail the results sad.gif We need to add another bit of code to the cron job so that the standard error (file descriptor 2) is also sent to /dev/null - we can do this by changing the code to
CODE
> /dev/null 2>&1

So the full cron job now looks like this
CODE
0,20,40 * * * * /usr/bin/php /var/www/vhosts/my.phpcoin.com/httpdocs/coin_cron/helpdesk.php > /dev/null 2>&1


Now thats all working, I can relax and have a coffee biggrin.gif biggrin.gif biggrin.gif - happy cron jobs !!!

Note 1 : Newer versions of phpCOIN now have the option to delete Imported Messages Only, or All Messages from an admin parameter.


--------------------
***** Unless otherwise stated, all replies refer to the following *****
====================================================================
--- The latest unmodified version of phpCOIN available from the phpCOIN download page on the date and time of this post.
--- All relevant HotFix files applied - One of the four included unmodified themes - The original language files .
--- Help will be given to install/configure/use phpCOIN, but not programming help to modify phpCOIN operations. If you are competent enough to make programming changes, you should be competent enough to read the source code and figure things out :)
PM
Top
beltane
Posted: January 06, 2010 04:18 pm
Quote Post


Newbie
*

Group: Probation
Posts: 1
Member No.: 4,131
Joined: January 06, 2010



Hi lightman,

Thank you for the tutorial! Here is another link for a good tutorial.
trap17

Unfortunately, between the two I still cannot get the cron job working right. Here is what I tried so far. Does anyone know of another tutorial that I can read?

---------------------------------------------

0 * * * * /usr/bin/php /www/mysite.com/hostbilling/coin_cron/invoices.php

/bin/sh: 0: command not found

--------------------------------------------

0 * * * * /usr/bin/php /var/www/mysite.com/hostbilling/coin_cron/invoices.php

/bin/sh: 0: command not found

----------------------------------------------

0 * * * * /usr/bin/php www/mysite.com/hostbilling/coin_cron/invoices.php

/bin/sh: 0: command not found

----------------------------------------------

0 * * * * /usr/bin/php /var/www/vhosts/mysite.com/httpdocs/coin_cron/invoices.php

/bin/sh: 0: command not found

-----------------------------------------------

/usr/bin/php /www/mysite.com/httpdocs/coin_cron/invoices.php

Status: 404 Not Found
X-Powered-By: PHP/5.2.9
Content-type: text/html

No input file specified.

-----------------------------------------------

/usr/bin/php 'http://mysite.com/httpdocs/coin_cron/invoices.php'

Status: 404 Not Found
X-Powered-By: PHP/5.2.9
Content-type: text/html

No input file specified.

------------------------------------------------
PMEmail Poster
Top
lightman
Posted: January 06, 2010 04:31 pm
Quote Post


The Janitor
***

Group: Admin
Posts: 3,639
Member No.: 3
Joined: August 25, 2006



Your results would suggest that either the path to the php executable on your server is NOT /usr/bin/php (the article that you linked to suggested that it might be /usr/local/bin/php on a cPanel server - I cant confirm nor deny this, I don't use cPanel - it is your server - you should know where the exectuables are on your own box !!)

OR

The user that you are running the php call under, does not have the necessary permissions to run php directly or can run php but not access the vhost file ???

Either way - if you are not sure - ask your server administrator - if they cant/wont help - I can only suggest using another hosting company that can/will - or - if you administrate the box yourself, there aren't many options other than a steep, and necessarily rapid, learning curve biggrin.gif

Also you might be interested in http://docs.phpcoin.com/index.php/Cron#Set...N_LAMP_cron_job

A quick way of checking cron jobs is to open a console into the server shell, and command line test the commands you are trying to run under a variety of available sudo users - pipe the output to a conveniently placed txt file if you want a record of what the command did - if non of this makes any sense - I do suggest you get someone to do this for you smile.gif


--------------------
***** Unless otherwise stated, all replies refer to the following *****
====================================================================
--- The latest unmodified version of phpCOIN available from the phpCOIN download page on the date and time of this post.
--- All relevant HotFix files applied - One of the four included unmodified themes - The original language files .
--- Help will be given to install/configure/use phpCOIN, but not programming help to modify phpCOIN operations. If you are competent enough to make programming changes, you should be competent enough to read the source code and figure things out :)
PM
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 


Inscrita el Registro Mercantil de Mallorca Tomo 2140, Hoja No. PM-51034, Folio 135
This website owned and operated by: Technology Services RPVW S.L. CIF# B57345084
Avda Constitucion 48 Bajos Alaro 07340 Baleares SPAIN
Tel:+34 971518362    Fax: +34 971518368    eMail: support@phpcoin.com