Solved

Cron Job Includes

Posted on 2012-04-06
2
245 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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

18 Experts available now in Live!

Get 1:1 Help Now