Solved

Cron Job Includes

Posted on 2012-04-06
2
281 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

631 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