The MU forums have moved to WordPress.org

Running a console script (8 posts)

  1. Detective
    Member
    Posted 14 years ago #

    Using regular WordPress, I can create console PHP scripts just including wp-config.php and accessing WordPress' functions. Those scripts are mainly cronjobs that perform maintenance.

    However, in MU I can't do this. The scripts ends execution.

    The last script I wanted to run was a converter from a stand-alone installation of bbPress to a new BuddyPress installation.

    <?php
    define( 'WP_USE_THEMES', false );
    $blog_id = 1;
    require( dirname( __FILE__ ) . '/html/wp-config.php' );
    do_action( 'bbpress_init' );
    remove_all_actions( 'bbpress_init' );
    /*
    code that fetchs the forum data and correctly inserts
    them in the new installation
    */
    ?>

    If I run the script accessing via HTTP everything works OK. If I run it on the console by typing:

    php bbpress_importer.php

    Execution ends inmediately.

    This does not happen with regular WordPress. Any clue? Does anybody have had a similar problem?

    Thanks.

  2. tdjcbe
    Member
    Posted 14 years ago #

    Have to admit I've not seen that practice before. I've always seen /wp-blog-header.php be the file called. Take a look at the root directory's index.php file for usage.

  3. andrea_r
    Moderator
    Posted 14 years ago #

    "The last script I wanted to run was a converter from a stand-alone installation of bbPress to a new BuddyPress installation. "

    There's a new option in the latest buddypress to hook up a pre-existing bbPress install. It's under the BuddyPress menu, under Forums setup. Not sure how well it works.

  4. Detective
    Member
    Posted 14 years ago #

    Andrea, the BuddyPress usage is not what I need. And also I need more console scripts to work, not just this one :)

    tdjcbe, it's not a common practice ;). For example, I run a cronjob to extract statistics every day. Loading wp-blog-header and looking at index.php only gives you the conclusion that the best file to load in a script is wp-config.php.

    The WP cron system is not suitable for stuff that needs to be done exactly at the same time every day, because it relies on http requests and it's still a process under the webserver. Sometimes you need to run a script under your user and not apache, without security restrictions or limited permissions.

    There are many scenarios where this stuff is useful. And in single WP it works right out the box. I tried to track the problem, without luck :(

  5. SteveAtty
    Member
    Posted 14 years ago #

    There was a change in one of the core WPMU files which means that command line executed php no longer works. The only way to do it is basically clone two or three of the core files and edit one single line in one of them and then change your file so it doesn't use wp-config.php but a different file.

    I documented it here:

    http://mu.wordpress.org/forums/topic/14750?replies=4

  6. Detective
    Member
    Posted 14 years ago #

    Thanks, Steve!! I tried to search the forum, but it seems I didn't use the right keywords.

    Thanks again :)

  7. error
    Member
    Posted 14 years ago #

    If you set $_SERVER['HTTP_HOST'] yourself before loading up wp-blog-header.php then everything works fine. Set it to the vhost of the blog you want your script to operate on. (If you're using subdirectories you're on your own.)

  8. error
    Member
    Posted 14 years ago #

    I take this back, in part.

    If you set $_SERVER['HTTP_HOST'] before loading up wp-blog-header.php then things work fine (for me) when the PHP script is called from the command line. But when it's called from the web server, it outputs the entire content of the main page of the site before continuing on with my script. This is definitely unwanted, and I haven't figured out how to work around this yet.

About this Topic