Support » Everything else WordPress » Can not load load-wp.php from command line

  • Resolved ahmetax

    (@ahmetax)


    Hello,
    I am using v4.0 multisite.
    I want to run a php script as a cron job.
    The php script runs without any problems on the browser.
    However I want to run it once everyday.
    When the script is called as a cron job, the process is being killed when it tries to load wp-load.php.
    Here is the code sample in order to load wp-load.php

    <?php
    $_SERVER['HTTP_HOST'] = 'localhost';
    if( ! defined( 'STDIN' ) )
    	die( 'This script can only be called from the command line.' );
    set_time_limit( 0 );
    ini_set( 'display_errors', 'off' );
    error_reporting(-1);
    define('WP_USE_THEMES', false);
    require_once( dirname( __FILE__ ) . '/wp-load.php' );
    ......
    ?>

    Cpanel cron command is as follows:

    cd /home/myweb/public_html/ ; /usr/local/bin/php -q  /home/myweb/public_html/myscript.php

    There are no problems in the cron job.
    But script does not include wp-load.php.
    What can I do?
    (In my system W3T Cache is running.)

Viewing 1 replies (of 1 total)
  • Thread Starter ahmetax

    (@ahmetax)

    I solved my problem.
    In order to load wp-db.php there are some prerequisites in WordPress 4.0. They are as follows:

    define('WPINC','public_html/wp-includes');
    define('WP_USE_THEMES', false);
    
    define('FROM_CRON',true);
    wp-config.php
    wp-includes/version.php
    wp-includes/plugin.php
    wp-includes/functions.php
    wp-includes/load.php
    
    wp-includes/wp-db.php
    $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

    ….

    FROM_CRON is used to stop loading wp-settings.php when called from the cron job. It is used in config.php as:

    if ( !( defined(‘FROM_CRON’) && FROM_CRON ) ) require_once(ABSPATH . ‘wp-settings.php’);

    Now I can run my script as a cron job without any problems.

    ahmet aksoy

Viewing 1 replies (of 1 total)
  • The topic ‘Can not load load-wp.php from command line’ is closed to new replies.