Closed Thread
Results 1 to 6 of 6

Thread: Include issues with Cron Jobs

  1. #1
    chewett's Avatar
    chewett is offline x10 Sophmore chewett is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    129

    Include issues with Cron Jobs

    Im currently using a cron job to run a script each time, So far so good.

    It runs the script using the following cron command

    PHP Code:
    /usr/bin/php   /home/chewett/public_html/dir/file.php >>/home/chewett/public_html/cronlog.txt  2>&
    But the problem occurs when my file is run, because i have includes in the file.

    I am trying to include

    /home/chewett/public_html/dir2/file2.php using include($_SERVER['DOCUMENT_ROOT'] . "/dir2/file2.php")

    But it always says it cannot find the file. I found a very old topic sugesting to cd to the root of my directory, but after trying this still get the same error

    I hope someone can advise me how i should call the command, or how my includes should be set up.

    Also, to clarify the script works perfectly fine when run normally

    Thanks for any help you might give! +rep for usefulness

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,635

    Re: Include issues with Cron Jobs

    Could you cut/paste the exact error message that shows up in the log?
    Nothing is always absolutely so.

  3. #3
    chewett's Avatar
    chewett is offline x10 Sophmore chewett is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    129

    Re: Include issues with Cron Jobs

    Current Cron Command

    PHP Code:
    /usr/bin/php   /home/chewett/public_html/SoE/curl/get_logs.php >>/home/chewett/public_html/cronlog.txt  2>&
    Error:

    PHP Code:
    X-Powered-ByPHP/5.2.14
    Content
    -typetext/html

    <br />
    <
    b>Warning</b>:  require_once(/curl/curl.php) [<a href='function.require-once'>function.require-once</a>]: failed to open streamNo such file or directory in <b>/home/chewett/public_html/SoE/curl/get_logs.php</bon line <b>8</b><br />
    <
    br />
    <
    b>Fatal error</b>:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/curl/curl.php' (include_path='.:/usr/lib/php:/usr/local/lib/php'in <b>/home/chewett/public_html/SoE/curl/get_logs.php</bon line <b>8</b><br /> 
    my include statement is

    PHP Code:
    require_once($_SERVER['DOCUMENT_ROOT'] . "/curl/curl.php"); 

    Hopefully there is either a different way i can code my includes, or an addtional part of my cron to call, I was trying to use.

    cd /home/chewett/public_html ; + the above command but that didnt seem to help either

    If the script runs successfully it should output something like

    Got logs at :2011_04_30_22_33

    which it does when visiting the page normally.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,635

    Re: Include issues with Cron Jobs

    require_once("/home/chewett/public_html/curl/curl.php");

    OR

    require_once("../curl/curl.php");

    Unless I am wrong, the $_SERVER['DOCUMENT_ROOT'] is only set if script is run via the Web (document root is a web server concept)

    Not sure if there is another super-global that you can use from the command line. I will run a few tests and see.
    Nothing is always absolutely so.

  5. #5
    chewett's Avatar
    chewett is offline x10 Sophmore chewett is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    129

    Re: Include issues with Cron Jobs

    thanks, both of them got it working, closed
    Last edited by chewett; 04-30-2011 at 05:15 PM.

  6. #6
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,635

    Re: Include issues with Cron Jobs

    $_ENV[ 'PWD' ] will give you '/home/chewett' (since it is running in your 'home directory' ). That is the best I could find for either $_ENV or $_SERVER ( $_ENV['PHP_SELF'] shows as not being set on my test account ).
    Nothing is always absolutely so.

Closed Thread

Similar Threads

  1. Cron Jobs
    By tubeclicks36 in forum Free Hosting
    Replies: 1
    Last Post: 01-31-2011, 02:37 PM
  2. Cron Jobs
    By rizla in forum Free Hosting
    Replies: 2
    Last Post: 01-04-2011, 05:59 PM
  3. Cron Jobs
    By lordsatw in forum Programming Help
    Replies: 9
    Last Post: 06-06-2009, 10:17 AM
  4. Cron Jobs
    By netengr in forum Free Hosting
    Replies: 0
    Last Post: 01-31-2008, 07:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers