Solved

Cron Job Includes

Posted on 2012-04-06
2
252 Views
Last Modified: 2012-08-21
I have the following cron setup on my server:

php -q /var/www/vhosts/inboxreach.com/httpdocs/MailPlatform/lib/crons/mailings_load.php

This cron job requires classes located in
/var/www/vhosts/inboxreach.com/httpdocs/MailPlatform/lib/classes/

Let's say I have class A, class B, and class C that are required in the cron script.  All three class objects are created on the cron script.  I then call out a method from Class A and use the global keyword to include the class B object and make a call to a Class B function.  This works fine.  However, when I make a call to class C and try and use global to include the class B object it fails.

I've tried including the class B file at the top of the class C file so that I can initiate a new object, but I keep getting require_once errors as I do not fully understand how to include a file if the include_path is the current directory and I need to go up a level.
0
Comment
Question by:kageboy2003
2 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 37818784
CRON jobs do not always have the same directory structure as the WWW root.  Try running this script as a CRON job (shown here in its entirety) to get a sense of the CRON environment.  You may be able to use more explicit include() statements once you see the directory structure.
<?php
ob_start();
phpinfo();
$msg = ob_get_clean();
mail ('you@your.org', 'CRON ENV', $msg);

Open in new window

0
 
LVL 33

Accepted Solution

by:
Slick812 earned 250 total points
ID: 37820325
greetings  kageboy2003, ,  I have tried to use PHP cron timed scripts on different host servers, there were some differences for me to get them working on different host servers, due to how the CRON was setup on the linux operating  system, as far as I know cron is outside of Apache and PHP.
What I do now, is for ANY require or include in a php cron script, I ALWAYS use the FULL file path in the include statement, like this -

include '/home/domain/cron/tclear.php';

on some servers the CRON is NOT set up to use the PHP file permissions or locations, but uses what it is set for outside of Apache and PHP..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now