Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

Cron Job Includes

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
kageboy2003
Asked:
kageboy2003
2 Solutions
 
Ray PaseurCommented:
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
 
Slick812Commented:
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now