[RESOLVED] Running "require" with a cron job
Results 1 to 7 of 7

Thread: [RESOLVED] Running "require" with a cron job

  1. #1
    Senior Member
    Join Date
    Mar 2010
    Posts
    327

    resolved [RESOLVED] Running "require" with a cron job

    Hi all:

    I have a php script that I am running using s cron job. It contains the following include:

    PHP Code:
    require($_SERVER['DOCUMENT_ROOT'].'/scr/scrSanitize.php'); 
    This is not being recognized when running as a cron job. The following page is a good thread on this subject, but I cannot figure out how to get their answer to work for me.


    http://stackoverflow.com/questions/2100545/serverdocument-root-does-not-work-in-the-php-script-running-through-cron


    So how does one recode require($_SERVER['DOCUMENT_ROOT'].'/scr/scrSanitize.php'); so it works on a cron job?

    Thanks !

  2. #2
    Senior Member
    Join Date
    Oct 2005
    Location
    Chicago, IL
    Posts
    463
    you need the full path starting at '/'.
    Bob Lob Law

  3. #3
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,478
    If you are running the script via the command line (e.g. called from the cron job as something like "php path/to/file.php") then there is no web server involved, so $_SERVER variables won't exist (or at least won't be populated). Therefore you'll need to reference the required file via a relative or absolute file system path.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,478
    Quote Originally Posted by jeepin81 View Post
    you need the full path starting at '/'.
    Or a relative path, likely using "../", or "../../", etc., to get down to what would be the document root if it were being run as a web page.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  5. #5
    Senior Member
    Join Date
    Oct 2005
    Location
    Chicago, IL
    Posts
    463
    wont the absolute root path start with '/'?
    Bob Lob Law

  6. #6
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,478
    Quote Originally Posted by jeepin81 View Post
    wont the absolute root path start with '/'?
    Yes (unless it's on Windoze). But you do not have to use a full path to require/include a file. It all depends on what the complete story is here and how portable the script needs to be.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  7. #7
    Senior Member
    Join Date
    Mar 2010
    Posts
    327
    Thanks all! The following worked!

    require('/home/myusername/public_html/scr/scrSanitize.php');

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •