SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My cron job refuses to work

    I created a php script called uawfixer.php that is located at my site's root directory. Its purpose is update the wp_posts table of my Wordpress install. Here is the line of code at the beginning of my script.
    Code:
    <?php
    extract($HTTP_SERVER_VARS);//extracts server varibles
    require_once($DOCUMENT_ROOT.'/blog/wp-config.php');//loads wp DB settings
    require_once($DOCUMENT_ROOT.'/blog/wp-blog-header.php');//loads functions
    .......[rest of code left of]......
    ?>
    I know the script works because it executes correctly when I access it directly from my browser.

    This script was placed into a cron tab vie cpanel using the following command:
    Code:
    php '/home/[account name removed]/public_html/uawfixer.php' > /dev/null ;
    The cron was set to run every minutes for testing. Unfortunately, this cron job produces error logs that say the following:
    [15-Sep-2008 04:01:02] PHP Warning: require_once(/blog/wp-config.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /home/[account name removed]/public_html/uawfixer.php on line 3
    [15-Sep-2008 04:01:02] PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/blog/wp-config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/[account name removed]/public_html/uawfixer.php on line 3
    I know "wp-config.php" exist because its is one of Wordpress's core files.

    Why won't this script work in cron; but work when accessed by the browser?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Instead of "$document_root", what happens if you write in the actual path to the file? (starting at "/home/ ..... "

    Does it still come out with the same error?

    Check if the quoted php include_path='.:/usr/lib/php:/usr/local/lib/php' you have shown is the same path as in your normal php.ini.

    If so, you may have two php.ini files at work.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by horusprim View Post

    Why won't this script work in cron; but work when accessed by the browser?
    Because you're executing php via the cli, and theres some differences between running php through a webserver.
    http://www.php.net/features.commandline

    In particular for your problem, php doesn't change it's current working directory like it does when run in a webserver. So you need to use full filesystem paths, or you need to set the working directory to a location where you will use relative filesystem paths.

    PHP Code:
    // change working dir to the dir this script is in
    chdir(dirname(__FILE__)); 
    php will also be using a different php.ini file. Things like document root, and many other variables don't exist because they often don't make sense in this enviornment.


Bookmarks

Posting Permissions

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