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

  • Resolved ahmetax


    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

    $_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' );
    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


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

    define('WP_USE_THEMES', false);
    $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.