Solved

Cron Job Includes

Posted on 2012-04-06
2
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 110

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 34

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

749 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